﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ToolBoxPro;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Globalization;
using LinqObj;
using System.Linq;
using System.Collections.Generic;

public partial class shoppingcart : RedirectPage
{
    public int propertyID;
    private IDictionary<int, Service_Category> categoryList;
    private ServiceListBuilder builder;
    public Control divOrderList;
    public Property property;
    private Campaign campaign;
    public Vendor_Detail vendor;
    public List<Order> orderList;
    private Button postBackBt;
    private Button submitBt;
    private Agent_Group group;

    private ToolboxDataContext tlfp = new ToolboxDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {

        // To prevent the browser to cache the page.
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
        Response.Cache.SetExpires(DateTime.MinValue);

        string getid = FPMoreInfoLinkID.Value;

        string t = null;

        
        if (Request.Form["task_num"] != null)
            t = Request.Form["task_num"].ToString();
        else if (Request.QueryString["task_num"] != null)
            t = Request.QueryString["task_num"];

        if (Request.QueryString["pid"] != null && Request.QueryString["pid"].ToString().Trim() != "")
            t = Request.QueryString["pid"].ToString().Trim();

        if ((t == "" || t == null) && PreviousPage != null) // && PreviousPage.Page is property)
        {
            HiddenField hd = (HiddenField)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("hd_PropertyID");
            if (hd != null)
                t = hd.Value.ToString();
        }

        if (t != null && t != "")
        {
            this.propertyID = Convert.ToInt32(t);
            this.property = Property.GetProperty(propertyID, Convert.ToInt32(Session[FormContract.AGENT_GROUP_ID]));
            if (this.property == null)
                return;
            refresh();
        }

        if (!Page.IsPostBack)
        {
            ((Label)Master.FindControl("lblTitle")).Text = "Shopping Cart";
            ((System.Web.UI.HtmlControls.HtmlImage)Master.FindControl("imgHeading")).Src = "images/buy.gif";
        }
    }

    private void refresh()
    {
        this.phServiceList.Controls.Clear();
        this.phOrderedList.Controls.Clear();

        if (categoryList == null)
        {
            categoryList = Service_Category.LoadServiceCategories(Session[FormContract.AGENT_GROUP_ID].ToString());
            builder = new ServiceListBuilder(categoryList);
        }

        this.campaign = Campaign.GetCurrentCampaignByProperty(this.propertyID);

        if (this.campaign == null)
        {
            this.campaign = new Campaign();
            this.campaign.agent_id = Convert.ToInt32(((Agent)Session[FormContract.AGENT]).agent_id.ToString());
            this.campaign.property_id = this.propertyID;
            this.campaign.user_id = ((Toolbox_User)Session[FormContract.USER]).user_id;
            Campaign.AddCampaign(campaign);
            Campaign.SubmitChanges();
        }

        //this.orderList = Order.LoadOrderList(propertyID, Campaign.STATUS_INACTIVE);
        this.orderList = campaign.GetOrders();

        //string str = BRDGetValues.Value;
        //int i = 0;

        //if (str != "")
        //{
        //    string[] htmlval = str.Split('~');

        //    if (htmlval[6].ToString() == "true" || htmlval[7].ToString() == "true")
        //    {
        //        i = 110;
        //    }

        //    if (htmlval[8].ToString() == "true")
        //    {
        //        i = i + 80;
        //    }

        //    if (ViewState["price"] == null)
        //        ViewState["price"] = i;
        //    else
        //        ViewState["price"] = Int32.Parse(ViewState["price"].ToString()) + i;
        //}

        //OrderListBuilder orderBuilder = new OrderListBuilder(orderList, this.property, categoryList, i);
        OrderListBuilder orderBuilder = new OrderListBuilder(orderList, this.property, categoryList);

        this.vendor = property.Vendor_Detail;
        this.divOrderList = orderBuilder.divOrderList;

        this.phServiceList.Controls.Add(builder.BuildServiceList());
        this.phOrderedList.Controls.Add(orderBuilder.BuildOrderList());
        this.phOrderedList.EnableViewState = false;
        //this.lbVendorInfo.InnerHtml = vendor.VendorDetail;
        this.propertyInfo.InnerText = this.property.PropertyInfo;
        this.lbVendorStatus.InnerText = property.VendorStatusLabel;

        maintainStatusBar();
        //bindEventHandler();
    }

    private void maintainStatusBar()
    {
        this.bt_ChangeStatus.Visible = true;
        this.bt_ChangeStatus.Enabled = true;
        this.lb_PropertyStatus.Text = "";
        //this.bt_ChangeStatus.Text = "Send Orders";
        //this.bt_Activate.Visible = true;
        //this.bt_Activate.Enabled = false;
        if (this.property._AllocatedStatus.Equals(Property.ALLOCATE_SAVED, StringComparison.CurrentCultureIgnoreCase))
        {
            this.lb_PropertyStatus.Text = "Orders list saved.";
            imgsaved.Visible = true;
            //if (this.property._CampaignStatus.Equals(Property.STATUS_INACTIVE, StringComparison.CurrentCultureIgnoreCase))
            //    this.bt_Activate.Enabled = true;
        }

        if (this.property._AllocatedStatus.Equals(Property.ALLOCATE_ORDERD, StringComparison.CurrentCultureIgnoreCase))
            this.bt_ChangeStatus.Enabled = false;
    }    

    protected void bt_Submit_Click(object sender, ImageClickEventArgs e)
    {
        saveProposedShoppingCart();
    }

    protected void bt_GetProposeForm_Click1(object sender, ImageClickEventArgs e)
    {
        saveProposedShoppingCart();
        //Server.Transfer("~/propose_form.aspx");
        Server.Transfer("~/propose_form.aspx?pid=" + this.propertyID);
    }

    protected void bt_ChangeStatus_Click(object sender, ImageClickEventArgs e)
    {
        this.property.SetCampaignStatus(Campaign.STATUS_CURRENT);
        Property.SubmitChanges();

        saveProposedShoppingCart();
        
        Order.LoadOrderList(this.propertyID, Property.STATUS_ACTIVE);
        
        foreach (Order order in this.orderList)
        {
            //order.SendOrder();
            SendOrder(order.order_id, order.service_id);
            Campaign.StatusToSent(order.order_id);
        }
        
        this.property.SetAllocatedStatus(Property.ALLOCATE_ORDERD);
        this.campaign.SetCampaignStatus(Campaign.STATUS_CURRENT);
        
        Campaign.SubmitChanges();
        Property.SubmitChanges();
        //SendUserMail();
        SendOrderEmail();
        //Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "alert('Order sent successfully.')", true);

        Response.Redirect("propertylist.aspx?msg=ordersent");
        //refresh();
    }

    private void saveProposedShoppingCart()
    {
        int count = 0;
        List<Order> dbOrderList = new List<Order>();
        campaign = Campaign.GetCurrentCampaignByProperty(this.propertyID);
        if (this.property == null)
            return;
        this.property.SetAllocatedStatus(Property.ALLOCATE_SAVED);
        Property.Insert_Update(property);

        foreach (string key in Request.Form.AllKeys)
        {
            if (key.StartsWith(Order.PREFIX))
            {
                string categoryIDKey = key;
                Order order = new Order();
                order.service_id = Convert.ToInt32(categoryIDKey.Remove(0, Order.PREFIX.Length));
                dbOrderList.Add(order);

                //string _date = Request.Form[Order.DUE_PREFIX + order.service_id].Trim().ToString();
                string test = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.ToString();
                order.order_date = DateTime.Now;

                //if (_date != "")
                //   order.due_date = DateTime.Parse(_date, CultureInfo.CurrentCulture);

                order.campaign_id = campaign.campaign_id;
                order.order_status = Order.STATUS_PROPOSE;
                order.agent_id = ((Agent)Session[FormContract.AGENT]).agent_id;
                count++;
            }
        }

        campaign.SaveOrders(dbOrderList);
        //Order.SaveOrderList( dbOrderList, campaign.CampaignID);
        refresh();
    }    

    protected void GenerateDivFP_Click(object sender, EventArgs e)
    {
        saveProposedShoppingCart();

        string getid = FPMoreInfoLinkID.Value;
        string[] splitid = getid.Split('_');
        string generatedivid = splitid[0] + "Div" + splitid[2];
        string generateOkHyperlinkid = splitid[0] + "_moreinfoOk_" + splitid[2];
        string generateCloseHyperlinkid = splitid[0] + "_moreinfoClose_" + splitid[2];

        int serviceid = Int32.Parse(splitid[2]);
        
        var orderid = (from a in tlfp.GetTable<Order>()
                       where a.campaign_id == campaign.campaign_id && a.service_id == serviceid
                       select a).Single();

        var searchFPTable = from b in tlfp.GetTable<FloorPlanMoreInfo>()
                            where b.ServiceID == serviceid && b.OrderID == orderid.order_id   
                            select b;

        string strdate = "", strtime = "", artdate = "", addinf0 = "", file1 = "", file2 = "", file3 = "", daytime = "", h = "0", m = "0";

        if (searchFPTable.Count() > 0)
        {
            strdate = String.Format("{0:dd/MM/yyyy}", searchFPTable.Single().ServiceDate);
            strtime = searchFPTable.Single().ServiceTime.ToString();
            string[] time = strtime.Split('-');

            if (strtime.IndexOf('-') > 0)
            {
                h = time[0];
                m = time[1];
                daytime = time[2];
            }

            artdate = String.Format("{0:dd/MM/yyyy}", searchFPTable.Single().ArtWorkDate);
            addinf0 = searchFPTable.Single().AdditionalInfo.ToString();
            
            if(searchFPTable.Single().File_1 != null)
                file1 = searchFPTable.Single().File_1.ToString();

            if (searchFPTable.Single().File_2 != null)
                file2 = searchFPTable.Single().File_2.ToString();

            if (searchFPTable.Single().File_3 != null)
                file3 = searchFPTable.Single().File_3.ToString();
        }

        HtmlGenericControl generatedDiv = new HtmlGenericControl("div");
        generatedDiv.Attributes["id"] = generatedivid;
        generatedDiv.Attributes["style"] = "visibility:visible;";
        generatedDiv.InnerHtml = "<div id='light' class='white_content'>";
        generatedDiv.InnerHtml += "<div class='popbrdwhite'>";
        generatedDiv.InnerHtml += "<div class='popbrdblack'>";
        generatedDiv.InnerHtml += "<table width='475' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td><table width='475' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='172' class='poptitle' style='padding-bottom:7px;'>Floor Plan</td>";
        generatedDiv.InnerHtml += "<td width='118' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='26' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='119' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='40' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Service Required</td>";
        generatedDiv.InnerHtml += "<td><input type='text' class='calenderdate' id='txtservice_" + splitid[2] + "' value='" + strdate + "' /></td>";
        
        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/calender.gif' width='18' height='18' /></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Enter time</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<select id='hours'>";

        for (int i = 1; i < 13; i++)
        {
            if(i == Int32.Parse(h))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + i + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + i + "</option>";
        }

        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";        
        generatedDiv.InnerHtml += "<select id='minutes'>";
        
        for (int i = 0; i < 60; i=i+15)
        {
            string timeval = i.ToString();

            if (timeval == "0")
                timeval = "00";

            if (i == Int32.Parse(m))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + timeval + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + timeval + "</option>";
        }
        
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";
        generatedDiv.InnerHtml += "<select id='daytime'>";
        
        if (daytime != "")
        {
            if (daytime == "AM")
            {
                generatedDiv.InnerHtml += "<option selected='selected'>AM</option>";
                generatedDiv.InnerHtml += "<option>PM</option>";
            }
            else
            {
                generatedDiv.InnerHtml += "<option>AM</option>";
                generatedDiv.InnerHtml += "<option selected='selected'>PM</option>";
            }
        }
        else
        {
            generatedDiv.InnerHtml += "<option>AM</option>";
            generatedDiv.InnerHtml += "<option>PM</option>";
        }
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/icon_time.gif' alt='' title='' /></td>";
        generatedDiv.InnerHtml += "</tr>";


        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Artwork Required</td>";
        generatedDiv.InnerHtml += "<td><input type='text' class='calenderdate'  class='popfild'  id='txtart_" + splitid[2] + "' value='" + artdate + "'  /></td>";
        generatedDiv.InnerHtml += "<td><img src='images/calender.gif' width='18' height='18'/></td>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td valign='top'>Additional Info</td>";
        generatedDiv.InnerHtml += "<td colspan='4'><textarea name='textarea' class='popfild' style='width:290px; height:80px;' id='txtarea_" + splitid[2] + "'>" + addinf0 + "</textarea></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td align='left' valign='top'>File Upload<br />";
        generatedDiv.InnerHtml += "<span style='font-size:10px; color:#999999; float:left;'>(Max 3 Uploads)</span></td>";
        generatedDiv.InnerHtml += "<td colspan='4' valign='top' style='padding-top:0px;'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
        //generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='60%'><input type='file' style='width:250px;' id='file1_" + splitid[2] + "'  name='file1_" + splitid[2] + "'  /></td>";
        generatedDiv.InnerHtml += "<td width='20%'>&nbsp;&nbsp;<a href=''></a></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td><input type='file' style='width:250px;' id='file2_" + splitid[2] + "'  name='file2_" + splitid[2] + "'  /></td>";
        generatedDiv.InnerHtml += "<td>&nbsp;&nbsp;<a href=''></a></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td><input type='file' style='width:250px;' id='file3_" + splitid[2] + "'  name='file3_" + splitid[2] + "' /></td>";
        generatedDiv.InnerHtml += "<td>&nbsp;&nbsp;<a href=''></a></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td colspan='4'>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoOk' href='#' id='" + generateOkHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/ok_btn.jpg' alt='' title='' style='margin-right:5px;' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoclose' href='#' id='" + generateCloseHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/cl_btn.jpg' border='0' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";  
        generatedDiv.InnerHtml += "</table>";                        
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "<div id='fade' class='black_overlay'>";
        generatedDiv.InnerHtml += "</div>";

        fpdiv.Controls.Add(generatedDiv);
    }

    protected void SubmitDivFP_Click(object sender, EventArgs e)
    {
        string str = FPGetValues.Value;
        string[] htmlval = str.Split('~');
        int i = campaign.campaign_id;

        var getorderid = (from a in tlfp.GetTable<Order>()
                          where a.campaign_id == campaign.campaign_id && a.service_id == Int32.Parse(htmlval[0].ToString())
                          select a).Single();

        var searchFPTable = from b in tlfp.GetTable<FloorPlanMoreInfo>()
                            where b.ServiceID == Int32.Parse(htmlval[0].ToString()) && b.OrderID == getorderid.order_id
                            select b;

        var getpropid = (from p in tlfp.GetTable<Campaign>()
                         where p.campaign_id == campaign.campaign_id
                         select p.property_id).Single();

        var getaddr = (from addr in tlfp.GetTable<Property>()
                       where addr.property_id == getpropid
                       select addr).Single();

        int agentGroupID = Convert.ToInt32(Session[FormContract.AGENT_GROUP_ID]);
        this.group = Agent_Group.GetAgentGroup(agentGroupID);

        string path = Server.MapPath("~/" + group.agent_group_name + "/" + getaddr.property_id + " " + getaddr.address1 + " " + getaddr.address2 + " " + getaddr.suburb + "\\UploadedFiles\\");

        HttpPostedFile file = Request.Files["file1_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[5].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file.FileName);
            file.SaveAs(path + fname);
        }

        HttpPostedFile file1 = Request.Files["file2_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[6].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file1.FileName);
            file1.SaveAs(path + fname);
        }

        HttpPostedFile file2 = Request.Files["file3_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[7].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file2.FileName);
            file2.SaveAs(path + fname);
        }

        FloorPlanMoreInfo fp;

        if (searchFPTable.Count() == 0)
        {
            fp = new FloorPlanMoreInfo();

            fp.ServiceID = Int32.Parse(htmlval[0].ToString());
            fp.OrderID = getorderid.order_id;
            
            if(htmlval[1].ToString() != "")
                fp.ServiceDate = DateTime.Parse(htmlval[1].ToString());
            
            fp.ServiceTime = htmlval[2].ToString();
            
            if (htmlval[3].ToString() != "")
                fp.ArtWorkDate = DateTime.Parse(htmlval[3].ToString());
            
            fp.AdditionalInfo = htmlval[4].ToString();

            if (htmlval[5].ToString() != "")
            {
                int index1 = htmlval[5].ToString().LastIndexOf("\\");
                string filname1 = htmlval[5].ToString().Substring(index1 + 1);
                fp.File_1 = filname1;
            }

            if (htmlval[6].ToString() != "")
            {
                int index2 = htmlval[6].ToString().LastIndexOf("\\");
                string filname2 = htmlval[6].ToString().Substring(index2 + 1);
                fp.File_2 = filname2;
            }

            if (htmlval[7].ToString() != "")
            {
                int index3 = htmlval[7].ToString().LastIndexOf("\\");
                string filname3 = htmlval[7].ToString().Substring(index3 + 1);
                fp.File_3 = filname3;
            }

            tlfp.GetTable<FloorPlanMoreInfo>().InsertOnSubmit(fp);
        }
        else
        {
            fp = searchFPTable.Single();
            
            if (htmlval[1].ToString() != "")
                fp.ServiceDate = DateTime.Parse(htmlval[1].ToString());
            
            fp.ServiceTime = htmlval[2].ToString();

            if (htmlval[3].ToString() != "")
                fp.ArtWorkDate = DateTime.Parse(htmlval[3].ToString());
            
            fp.AdditionalInfo = htmlval[4].ToString();

            if (htmlval[5].ToString() != "")
            {
                int index1 = htmlval[5].ToString().LastIndexOf("\\");
                string filname1 = htmlval[5].ToString().Substring(index1 + 1);
                fp.File_1 = filname1;
            }

            if (htmlval[6].ToString() != "")
            {
                int index2 = htmlval[6].ToString().LastIndexOf("\\");
                string filname2 = htmlval[6].ToString().Substring(index2 + 1);
                fp.File_2 = filname2;
            }

            if (htmlval[7].ToString() != "")
            {
                int index3 = htmlval[7].ToString().LastIndexOf("\\");
                string filname3 = htmlval[7].ToString().Substring(index3 + 1);
                fp.File_3 = filname3;
            }           
        }

        tlfp.SubmitChanges();
    }

    protected void GenerateDivDP_Click(object sender, EventArgs e)
    {
        saveProposedShoppingCart();

        string getid = DPMoreInfoLinkID.Value;
        string[] splitid = getid.Split('_');
        string generatedivid = splitid[0] + "Div" + splitid[2];
        string generateOkHyperlinkid = splitid[0] + "_moreinfoOk_" + splitid[2];
        string generateCloseHyperlinkid = splitid[0] + "_moreinfoClose_" + splitid[2];

        int serviceid = Int32.Parse(splitid[2]);

        var orderid = (from a in tlfp.GetTable<Order>()
                       where a.campaign_id == campaign.campaign_id && a.service_id == serviceid
                       select a).Single();

        var searchDPTable = from b in tlfp.GetTable<DiscountPhotoMoreInfo>()
                            where b.ServiceID == serviceid && b.OrderID == orderid.order_id
                            select b;

        string strdate = "", strtime = "", artdate = "", addinf0 = "", file1 = "", file2 = "", file3 = "", daytime = "", h = "0", m = "0";

        if (searchDPTable.Count() > 0)
        {
            strdate = String.Format("{0:dd/MM/yyyy}", searchDPTable.Single().ServiceDate);
            strtime = searchDPTable.Single().ServiceTime.ToString();
            string[] time = strtime.Split('-');

            if (strtime.IndexOf('-') > 0)
            {
                h = time[0];
                m = time[1];
                daytime = time[2];
            }

            artdate = String.Format("{0:dd/MM/yyyy}", searchDPTable.Single().ArtWorkDate);
            addinf0 = searchDPTable.Single().AdditionalInfo.ToString();

            if (searchDPTable.Single().File_1 != null)
                file1 = searchDPTable.Single().File_1.ToString();

            if (searchDPTable.Single().File_2 != null)
                file2 = searchDPTable.Single().File_2.ToString();

            if (searchDPTable.Single().File_3 != null)
                file3 = searchDPTable.Single().File_3.ToString();
        }

        HtmlGenericControl generatedDiv = new HtmlGenericControl("div");
        generatedDiv.Attributes["id"] = generatedivid;
        generatedDiv.Attributes["style"] = "visibility:visible;";
        generatedDiv.InnerHtml = "<div id='light' class='white_content'>";
        generatedDiv.InnerHtml += "<div class='popbrdwhite'>";
        generatedDiv.InnerHtml += "<div class='popbrdblack'>";
        generatedDiv.InnerHtml += "<table width='475' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td><table width='475' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td colspan='3' width='172' class='poptitle' style='padding-bottom:7px;'>Discount Photo and Plan Combo</td>";
        //generatedDiv.InnerHtml += "<td width='118' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        //generatedDiv.InnerHtml += "<td width='26' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='119' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='40' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Service Required</td>";
        generatedDiv.InnerHtml += "<td><input type='text' class='calenderdate' id='txtservice_" + splitid[2] + "' value='" + strdate + "' /></td>";

        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/calender.gif' width='18' height='18' /></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Enter time</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<select id='hours'>";
        for (int i = 1; i < 13; i++)
        {
            if (i == Int32.Parse(h))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + i + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + i + "</option>";
        }
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";
        generatedDiv.InnerHtml += "<select id='minutes'>";

        for (int i = 0; i < 60; i = i + 15)
        {
            string timeval = i.ToString();

            if (timeval == "0")
                timeval = "00";

            if (i == Int32.Parse(m))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + timeval + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + timeval + "</option>";
        }

        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";
        generatedDiv.InnerHtml += "<select id='daytime'>";
        if (daytime != "")
        {
            if (daytime == "AM")
            {
                generatedDiv.InnerHtml += "<option selected='selected'>AM</option>";
                generatedDiv.InnerHtml += "<option>PM</option>";
            }
            else
            {
                generatedDiv.InnerHtml += "<option>AM</option>";
                generatedDiv.InnerHtml += "<option selected='selected'>PM</option>";
            }
        }
        else
        {
            generatedDiv.InnerHtml += "<option>AM</option>";
            generatedDiv.InnerHtml += "<option>PM</option>";
        }
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/icon_time.gif' alt='' title='' /></td>";
        generatedDiv.InnerHtml += "</tr>";


        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Artwork Required</td>";
        generatedDiv.InnerHtml += "<td><input type='text' class='calenderdate'  class='popfild'  id='txtart_" + splitid[2] + "' value='" + artdate + "'  /></td>";
        generatedDiv.InnerHtml += "<td><img src='images/calender.gif' width='18' height='18'/></td>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td valign='top'>Additional Info</td>";
        generatedDiv.InnerHtml += "<td colspan='4'><textarea name='textarea' class='popfild' style='width:290px; height:80px;' id='txtarea_" + splitid[2] + "'>" + addinf0 + "</textarea></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td align='left' valign='top'>File Upload<br />";
        generatedDiv.InnerHtml += "<span style='font-size:10px; color:#999999; float:left;'>(Max 3 Uploads)</span></td>";
        generatedDiv.InnerHtml += "<td colspan='4' valign='top' style='padding-top:0px;'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
        //generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='60%'><input type='file' style='width:250px;' id='file1_" + splitid[2] + "'  name='file1_" + splitid[2] + "'  /></td>";
        generatedDiv.InnerHtml += "<td width='20%'>&nbsp;&nbsp;<a href=''></a></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td><input type='file' style='width:250px;' id='file2_" + splitid[2] + "'  name='file2_" + splitid[2] + "'  /></td>";
        generatedDiv.InnerHtml += "<td>&nbsp;&nbsp;<a href=''></a></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td><input type='file' style='width:250px;' id='file3_" + splitid[2] + "'  name='file3_" + splitid[2] + "' /></td>";
        generatedDiv.InnerHtml += "<td>&nbsp;&nbsp;<a href=''></a></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td colspan='4'>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoOk' href='#' id='" + generateOkHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/ok_btn.jpg' alt='' title='' style='margin-right:5px;' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoclose' href='#' id='" + generateCloseHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/cl_btn.jpg' border='0' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "<div id='fade' class='black_overlay'>";
        generatedDiv.InnerHtml += "</div>";

        dpdiv.Controls.Add(generatedDiv);
    }

    protected void SubmitDivDP_Click(object sender, EventArgs e)
    {
        string str = DPGetValues.Value;
        string[] htmlval = str.Split('~');
        int i = campaign.campaign_id;

        var getorderid = (from a in tlfp.GetTable<Order>()
                          where a.campaign_id == campaign.campaign_id && a.service_id == Int32.Parse(htmlval[0].ToString())
                          select a).Single();

        var searchDPTable = from b in tlfp.GetTable<DiscountPhotoMoreInfo>()
                            where b.ServiceID == Int32.Parse(htmlval[0].ToString()) && b.OrderID == getorderid.order_id
                            select b;

        var getpropid = (from p in tlfp.GetTable<Campaign>()
                         where p.campaign_id == campaign.campaign_id
                         select p.property_id).Single();

        var getaddr = (from addr in tlfp.GetTable<Property>()
                       where addr.property_id == getpropid
                       select addr).Single();

        int agentGroupID = Convert.ToInt32(Session[FormContract.AGENT_GROUP_ID]);
        this.group = Agent_Group.GetAgentGroup(agentGroupID);

        string path = Server.MapPath("~/" + group.agent_group_name + "/" + getaddr.property_id + " " + getaddr.address1 + " " + getaddr.address2 + " " + getaddr.suburb + "\\UploadedFiles\\");

        HttpPostedFile file = Request.Files["file1_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[5].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file.FileName);
            file.SaveAs(path + fname);
        }

        HttpPostedFile file1 = Request.Files["file2_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[6].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file1.FileName);
            file1.SaveAs(path + fname);
        }

        HttpPostedFile file2 = Request.Files["file3_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[7].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file2.FileName);
            file2.SaveAs(path + fname);
        }

        DiscountPhotoMoreInfo dp;

        if (searchDPTable.Count() == 0)
        {
            dp = new DiscountPhotoMoreInfo();

            dp.ServiceID = Int32.Parse(htmlval[0].ToString());
            dp.OrderID = getorderid.order_id;

            if (htmlval[1].ToString() != "")
                dp.ServiceDate = DateTime.Parse(htmlval[1].ToString());

            dp.ServiceTime = htmlval[2].ToString();

            if (htmlval[3].ToString() != "")
                dp.ArtWorkDate = DateTime.Parse(htmlval[3].ToString());

            dp.AdditionalInfo = htmlval[4].ToString();

            if (htmlval[5].ToString() != "")
            {
                int index1 = htmlval[5].ToString().LastIndexOf("\\");
                string filname1 = htmlval[5].ToString().Substring(index1 + 1);
                dp.File_1 = filname1;
            }

            if (htmlval[6].ToString() != "")
            {
                int index2 = htmlval[6].ToString().LastIndexOf("\\");
                string filname2 = htmlval[6].ToString().Substring(index2 + 1);
                dp.File_2 = filname2;
            }

            if (htmlval[7].ToString() != "")
            {
                int index3 = htmlval[7].ToString().LastIndexOf("\\");
                string filname3 = htmlval[7].ToString().Substring(index3 + 1);
                dp.File_3 = filname3;
            }

            tlfp.GetTable<DiscountPhotoMoreInfo>().InsertOnSubmit(dp);
        }
        else
        {
            dp = searchDPTable.Single();

            if (htmlval[1].ToString() != "")
                dp.ServiceDate = DateTime.Parse(htmlval[1].ToString());

            dp.ServiceTime = htmlval[2].ToString();

            if (htmlval[3].ToString() != "")
                dp.ArtWorkDate = DateTime.Parse(htmlval[3].ToString());

            dp.AdditionalInfo = htmlval[4].ToString();

            if (htmlval[5].ToString() != "")
            {
                int index1 = htmlval[5].ToString().LastIndexOf("\\");
                string filname1 = htmlval[5].ToString().Substring(index1 + 1);
                dp.File_1 = filname1;
            }

            if (htmlval[6].ToString() != "")
            {
                int index2 = htmlval[6].ToString().LastIndexOf("\\");
                string filname2 = htmlval[6].ToString().Substring(index2 + 1);
                dp.File_2 = filname2;
            }

            if (htmlval[7].ToString() != "")
            {
                int index3 = htmlval[7].ToString().LastIndexOf("\\");
                string filname3 = htmlval[7].ToString().Substring(index3 + 1);
                dp.File_3 = filname3;
            }
        }

        tlfp.SubmitChanges();
    }

    protected void GenerateDivPH_Click(object sender, EventArgs e)
    {
        saveProposedShoppingCart();

        string getid = PHMoreInfoLinkID.Value;
        string[] splitid = getid.Split('_');
        string generatedivid = splitid[0] + "Div" + splitid[2];
        string generateOkHyperlinkid = splitid[0] + "_moreinfoOk_" + splitid[2];
        string generateCloseHyperlinkid = splitid[0] + "_moreinfoClose_" + splitid[2];

        int serviceid = Int32.Parse(splitid[2]);

        var orderid = (from a in tlfp.GetTable<Order>()
                       where a.campaign_id == campaign.campaign_id && a.service_id == serviceid
                       select a).Single();

        var searchPHTable = from b in tlfp.GetTable<PhotographyMoreInfo>()
                            where b.ServiceID == serviceid && b.OrderID == orderid.order_id
                            select b;

        string strdate = "", strtime = "", artdate = "", addinf0 = "", daytime = "", h = "0", m = "0";

        if (searchPHTable.Count() > 0)
        {
            strdate = String.Format("{0:dd/MM/yyyy}", searchPHTable.Single().ServiceDate);

            strtime = searchPHTable.Single().ServiceTime.ToString();
            string[] time = strtime.Split('-');

            if (strtime.IndexOf('-') > 0)
            {
                h = time[0];
                m = time[1];
                daytime = time[2];
            }

            artdate = String.Format("{0:dd/MM/yyyy}", searchPHTable.Single().ArtWorkDate);
            addinf0 = searchPHTable.Single().AdditionalInfo.ToString();
        }


        HtmlGenericControl generatedDiv = new HtmlGenericControl("div");
        generatedDiv.Attributes["id"] = generatedivid;
        generatedDiv.Attributes["style"] = "visibility:visible;";
        generatedDiv.InnerHtml = "<div id='light' class='white_content'>";
        generatedDiv.InnerHtml += "<div class='popbrdwhite'>";
        generatedDiv.InnerHtml += "<div class='popbrdblack'>";
        generatedDiv.InnerHtml += "<table width='475' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td><table width='475' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='172' class='poptitle' style='padding-bottom:7px;'>Photography</td>";
        generatedDiv.InnerHtml += "<td width='118' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='26' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='119' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='40' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Service Required</td>";
        generatedDiv.InnerHtml += "<td><input type='text' class='calenderdate' id='txtservice_" + splitid[2] + "' value='" + strdate + "' /></td>";

        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/calender.gif' width='18' height='18' /></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Enter time</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<select id='hours'>";
        for (int i = 1; i < 13; i++)
        {
            if (i == Int32.Parse(h))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + i + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + i + "</option>";
        }
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";
        generatedDiv.InnerHtml += "<select id='minutes'>";

        for (int i = 0; i < 60; i = i + 15)
        {
            string timeval = i.ToString();

            if (timeval == "0")
                timeval = "00";

            if (i == Int32.Parse(m))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + timeval + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + timeval + "</option>";
        }

        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";
        generatedDiv.InnerHtml += "<select id='daytime'>";
        if (daytime != "")
        {
            if (daytime == "AM")
            {
                generatedDiv.InnerHtml += "<option selected='selected'>AM</option>";
                generatedDiv.InnerHtml += "<option>PM</option>";
            }
            else
            {
                generatedDiv.InnerHtml += "<option>AM</option>";
                generatedDiv.InnerHtml += "<option selected='selected'>PM</option>";
            }
        }
        else
        {
            generatedDiv.InnerHtml += "<option>AM</option>";
            generatedDiv.InnerHtml += "<option>PM</option>";
        }
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/icon_time.gif' alt='' title='' /></td>";
        generatedDiv.InnerHtml += "</tr>";

        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Artwork Required</td>";
        generatedDiv.InnerHtml += "<td><input type='text' class='calenderdate'  id='txtart_" + splitid[2] + "' value='" + artdate + "'  /></td>";
        generatedDiv.InnerHtml += "<td><img src='images/calender.gif' width='18' height='18'/></td>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td valign='top'>Additional Info</td>";
        generatedDiv.InnerHtml += "<td colspan='4'><textarea name='textarea' class='popfild' style='width:290px; height:80px;' id='txtarea_" + splitid[2] + "'>" + addinf0 + "</textarea></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td valign='top'></td>";
        generatedDiv.InnerHtml += "<td colspan='4'>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoOk' href='#' id='" + generateOkHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/ok_btn.jpg' alt='' title='' style='margin-right:5px;' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoclose' href='#' id='" + generateCloseHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/cl_btn.jpg' border='0' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "<div id='fade' class='black_overlay'>";
        generatedDiv.InnerHtml += "</div>";

        phdiv.Controls.Add(generatedDiv);
    }

    protected void SubmitDivPH_Click(object sender, EventArgs e)
    {
        string str = PHGetValues.Value;
        string[] htmlval = str.Split('~');
        int i = campaign.campaign_id;

        PhotographyMoreInfo ph; 

        var getorderid = (from a in tlfp.GetTable<Order>()
                          where a.campaign_id == campaign.campaign_id && a.service_id == Int32.Parse(htmlval[0].ToString())
                          select a).Single();

        var searchPHTable = from b in tlfp.GetTable<PhotographyMoreInfo>()
                            where b.ServiceID == Int32.Parse(htmlval[0].ToString()) && b.OrderID == getorderid.order_id
                            select b;

        if (searchPHTable.Count() == 0)
        {
            ph = new PhotographyMoreInfo();

            ph.ServiceID = Int32.Parse(htmlval[0].ToString());
            ph.OrderID = getorderid.order_id;

            if (htmlval[1].ToString() != "")
                ph.ServiceDate = DateTime.Parse(htmlval[1].ToString());
            
            ph.ServiceTime = htmlval[2].ToString();

            if (htmlval[3].ToString() != "")
                ph.ArtWorkDate = DateTime.Parse(htmlval[3].ToString());
            
            ph.AdditionalInfo = htmlval[4].ToString();

            tlfp.GetTable<PhotographyMoreInfo>().InsertOnSubmit(ph);
        }
        else
        {
            ph = searchPHTable.Single();

            if (htmlval[1].ToString() != "")
                ph.ServiceDate = DateTime.Parse(htmlval[1].ToString());
            
            ph.ServiceTime = htmlval[2].ToString();

            if (htmlval[3].ToString() != "")
                ph.ArtWorkDate = DateTime.Parse(htmlval[3].ToString());
            
            ph.AdditionalInfo = htmlval[4].ToString();
        }

        tlfp.SubmitChanges();
    }

    protected void GenerateDivCP_Click(object sender, EventArgs e)
    {
        saveProposedShoppingCart();

        string getid = CPMoreInfoLinkID.Value;
        string[] splitid = getid.Split('_');
        string generatedivid = splitid[0] + "Div" + splitid[2];
        string generateOkHyperlinkid = splitid[0] + "_moreinfoOk_" + splitid[2];
        string generateCloseHyperlinkid = splitid[0] + "_moreinfoClose_" + splitid[2];

        int serviceid = Int32.Parse(splitid[2]);

        var orderid = (from a in tlfp.GetTable<Order>()
                       where a.campaign_id == campaign.campaign_id && a.service_id == serviceid
                       select a).Single();

        var searchCPTable = from b in tlfp.GetTable<CopyWritingMoreInfo>()
                            where b.ServiceID == serviceid && b.OrderID == orderid.order_id
                            select b;

        string strdate = "", strtime = "", artdate = "", addinf0 = "", daytime = "", h = "0", m = "0";

        if (searchCPTable.Count() > 0)
        {
            strdate = String.Format("{0:dd/MM/yyyy}", searchCPTable.Single().ServiceDate);
            strtime = searchCPTable.Single().ServiceTime.ToString();
            string[] time = strtime.Split('-');

            if (strtime.IndexOf('-') > 0)
            {
                h = time[0];
                m = time[1];
                daytime = time[2];
            }
            artdate = String.Format("{0:dd/MM/yyyy}", searchCPTable.Single().ArtWorkDate);
            addinf0 = searchCPTable.Single().AdditionalInfo.ToString();
        }

        HtmlGenericControl generatedDiv = new HtmlGenericControl("div");
        generatedDiv.Attributes["id"] = generatedivid;
        generatedDiv.Attributes["style"] = "visibility:visible;";
        generatedDiv.InnerHtml = "<div id='light' class='white_content'>";
        generatedDiv.InnerHtml += "<div class='popbrdwhite'>";
        generatedDiv.InnerHtml += "<div class='popbrdblack'>";
        generatedDiv.InnerHtml += "<table width='475' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td><table width='475' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='172' class='poptitle' style='padding-bottom:7px;'>Copywriting</td>";
        generatedDiv.InnerHtml += "<td width='118' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='26' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='119' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='40' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Service Required</td>";
        generatedDiv.InnerHtml += "<td><input type='text' class='calenderdate' id='txtservice_" + splitid[2] + "' value='" + strdate + "' /></td>";

        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/calender.gif' width='18' height='18' /></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Enter time</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<select id='hours'>";
        for (int i = 1; i < 13; i++)
        {
            if (i == Int32.Parse(h))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + i + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + i + "</option>";
        }
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";
        generatedDiv.InnerHtml += "<select id='minutes'>";

        for (int i = 0; i < 60; i = i + 15)
        {
            string timeval = i.ToString();

            if (timeval == "0")
                timeval = "00";

            if (i == Int32.Parse(m))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + timeval + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + timeval + "</option>";
        }

        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";
        generatedDiv.InnerHtml += "<select id='daytime'>";
        if (daytime != "")
        {
            if (daytime == "AM")
            {
                generatedDiv.InnerHtml += "<option selected='selected'>AM</option>";
                generatedDiv.InnerHtml += "<option>PM</option>";
            }
            else
            {
                generatedDiv.InnerHtml += "<option>AM</option>";
                generatedDiv.InnerHtml += "<option selected='selected'>PM</option>";
            }
        }
        else
        {
            generatedDiv.InnerHtml += "<option>AM</option>";
            generatedDiv.InnerHtml += "<option>PM</option>";
        }
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/icon_time.gif' alt='' title='' /></td>";
        generatedDiv.InnerHtml += "</tr>";

        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Artwork Required</td>";
        generatedDiv.InnerHtml += "<td><input type='text' class='calenderdate'  id='txtart_" + splitid[2] + "' value='" + artdate + "'  /></td>";
        generatedDiv.InnerHtml += "<td><img src='images/calender.gif' width='18' height='18'/></td>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td valign='top'>Additional Info</td>";
        generatedDiv.InnerHtml += "<td colspan='4'><textarea name='textarea' class='popfild' style='width:290px; height:80px;' id='txtarea_" + splitid[2] + "'>" + addinf0 + "</textarea></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td align='left' valign='top'>File Upload<br />";
        generatedDiv.InnerHtml += "<span style='font-size:10px; color:#999999; float:left;'>(Max 1 Uploads)</span></td>";
        generatedDiv.InnerHtml += "<td colspan='4' valign='top' style='padding-top:0px;'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='60%'><input type='file' style='width:250px;' id='file1_" + splitid[2] + "'  name='file1_" + splitid[2] + "' /></td>";
        generatedDiv.InnerHtml += "<td width='20%'>&nbsp;&nbsp;<a href=''></a></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td colspan='4'>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoOk' href='#' id='" + generateOkHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/ok_btn.jpg' alt='' title='' style='margin-right:5px;' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoclose' href='#' id='" + generateCloseHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/cl_btn.jpg' border='0' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "<div id='fade' class='black_overlay'>";
        generatedDiv.InnerHtml += "</div>";

        cpdiv.Controls.Add(generatedDiv);
    }

    protected void SubmitDivCP_Click(object sender, EventArgs e)
    {
        string str = CPGetValues.Value;
        string[] htmlval = str.Split('~');
        int i = campaign.campaign_id;

        CopyWritingMoreInfo cp; 

        var getorderid = (from a in tlfp.GetTable<Order>()
                          where a.campaign_id == campaign.campaign_id && a.service_id == Int32.Parse(htmlval[0].ToString())
                          select a).Single();

        var searchCPTable = from b in tlfp.GetTable<CopyWritingMoreInfo>()
                            where b.ServiceID == Int32.Parse(htmlval[0].ToString()) && b.OrderID == getorderid.order_id
                            select b;

        var getpropid = (from p in tlfp.GetTable<Campaign>()
                         where p.campaign_id == campaign.campaign_id
                         select p.property_id).Single();

        var getaddr = (from addr in tlfp.GetTable<Property>()
                       where addr.property_id == getpropid
                       select addr).Single();

        int agentGroupID = Convert.ToInt32(Session[FormContract.AGENT_GROUP_ID]);
        this.group = Agent_Group.GetAgentGroup(agentGroupID);

        string path = Server.MapPath("~/" + group.agent_group_name + "/" + getaddr.property_id + " " + getaddr.address1 + " " + getaddr.address2 + " " + getaddr.suburb + "\\UploadedFiles\\");

        HttpPostedFile file = Request.Files["file1_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[5].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file.FileName);
            file.SaveAs(path + fname);
        }

        if (searchCPTable.Count() == 0)
        {
            cp = new CopyWritingMoreInfo();

            cp.ServiceID = Int32.Parse(htmlval[0].ToString());
            cp.OrderID = getorderid.order_id;

            if (htmlval[1].ToString() != "")
                cp.ServiceDate = DateTime.Parse(htmlval[1].ToString());
            
            cp.ServiceTime = htmlval[2].ToString();
            
            if (htmlval[3].ToString() != "")
                cp.ArtWorkDate = DateTime.Parse(htmlval[3].ToString());
            
            cp.AdditionalInfo = htmlval[4].ToString();

            if (htmlval[5].ToString() != "")
            {
                int index1 = htmlval[5].ToString().LastIndexOf("\\");
                string filname1 = htmlval[5].ToString().Substring(index1 + 1);
                cp.File_1 = filname1;
            }

            tlfp.GetTable<CopyWritingMoreInfo>().InsertOnSubmit(cp);
        }
        else
        {
            cp = searchCPTable.Single();

            if (htmlval[1].ToString() != "")
                cp.ServiceDate = DateTime.Parse(htmlval[1].ToString());
            
            cp.ServiceTime = htmlval[2].ToString();

            if (htmlval[3].ToString() != "")
                cp.ArtWorkDate = DateTime.Parse(htmlval[3].ToString());
            
            cp.AdditionalInfo = htmlval[4].ToString();

            if (htmlval[5].ToString() != "")
            {
                int index1 = htmlval[5].ToString().LastIndexOf("\\");
                string filname1 = htmlval[5].ToString().Substring(index1 + 1);
                cp.File_1 = filname1;
            }
        }

        tlfp.SubmitChanges();
    }

    protected void GenerateDivOTH_Click(object sender, EventArgs e)
    {
        saveProposedShoppingCart();

        string getid = OTHMoreInfoLinkID.Value;
        string[] splitid = getid.Split('_');
        string generatedivid = splitid[0] + "Div" + splitid[2];
        string generateOkHyperlinkid = splitid[0] + "_moreinfoOk_" + splitid[2];
        string generateCloseHyperlinkid = splitid[0] + "_moreinfoClose_" + splitid[2];

        int serviceid = Int32.Parse(splitid[2]);

        var orderid = (from a in tlfp.GetTable<Order>()
                       where a.campaign_id == campaign.campaign_id && a.service_id == serviceid
                       select a).Single();

        var searchOthTable = from b in tlfp.GetTable<OtherMoreInfo>()
                             where b.ServiceID == serviceid && b.OrderID == orderid.order_id
                             select b;

        string addinf0 = "";

        if (searchOthTable.Count() > 0)
        {
            addinf0 = searchOthTable.Single().AdditionalInfo.ToString();
        }

        HtmlGenericControl generatedDiv = new HtmlGenericControl("div");
        generatedDiv.Attributes["id"] = generatedivid;
        generatedDiv.Attributes["style"] = "visibility:visible;";
        generatedDiv.InnerHtml = "<div id='light' class='white_content'>";
        generatedDiv.InnerHtml += "<div class='popbrdwhite'>";
        generatedDiv.InnerHtml += "<div class='popbrdblack'>";
        generatedDiv.InnerHtml += "<table width='435' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td><table width='435' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='132' class='poptitle' style='padding-bottom:7px;'>Miscellaneous</td>";
        generatedDiv.InnerHtml += "<td width='118' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='26' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='119' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='40' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td valign='top'>Additional Info</td>";
        generatedDiv.InnerHtml += "<td colspan='4'><textarea name='textarea' class='popfild' style='width:290px; height:80px;' id='txtarea_" + splitid[2] + "'>" + addinf0 + "</textarea></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td style='padding: 10px 0 0 132px;'>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoOk' href='#' id='" + generateOkHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/ok_btn.jpg' alt='' title='' style='margin-right:5px;' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoclose' href='#' id='" + generateCloseHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/cl_btn.jpg' border='0' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "<div id='fade' class='black_overlay'>";
        generatedDiv.InnerHtml += "</div>";

        othdiv.Controls.Add(generatedDiv);
    }

    protected void SubmitDivOTH_Click(object sender, EventArgs e)
    {
        string str = OTHGetValues.Value;
        string[] htmlval = str.Split('~');
        int i = campaign.campaign_id;

        OtherMoreInfo oth; 

        var getorderid = (from a in tlfp.GetTable<Order>()
                          where a.campaign_id == campaign.campaign_id && a.service_id == Int32.Parse(htmlval[0].ToString())
                          select a).Single();

        var searchOthTable = from b in tlfp.GetTable<OtherMoreInfo>()
                             where b.ServiceID == Int32.Parse(htmlval[0].ToString()) && b.OrderID == getorderid.order_id
                             select b;

        if (searchOthTable.Count() == 0)
        {
            oth = new OtherMoreInfo();

            oth.ServiceID = Int32.Parse(htmlval[0].ToString());
            oth.OrderID = getorderid.order_id;
            oth.AdditionalInfo = htmlval[1].ToString();

            tlfp.GetTable<OtherMoreInfo>().InsertOnSubmit(oth);
        }
        else
        {
            oth = searchOthTable.Single();
            oth.AdditionalInfo = htmlval[1].ToString();
        }

        tlfp.SubmitChanges();
    }

    protected void GenerateDivBC_Click(object sender, EventArgs e)
    {
        saveProposedShoppingCart();

        string getid = BCMoreInfoLinkID.Value;
        string[] splitid = getid.Split('_');
        string generatedivid = splitid[0] + "Div" + splitid[2];
        string generateOkHyperlinkid = splitid[0] + "_moreinfoOk_" + splitid[2];
        string generateCloseHyperlinkid = splitid[0] + "_moreinfoClose_" + splitid[2];

        int serviceid = Int32.Parse(splitid[2]);

        var orderid = (from a in tlfp.GetTable<Order>()
                       where a.campaign_id == campaign.campaign_id && a.service_id == serviceid
                       select a).Single();

        var searchBCTable = from b in tlfp.GetTable<BrochureMoreInfo>()
                            where b.ServiceID == serviceid && b.OrderID == orderid.order_id
                            select b;

        string addinf0 = "";

        if (searchBCTable.Count() > 0)
        {
            addinf0 = searchBCTable.Single().AdditionalInfo.ToString();
        }

        HtmlGenericControl generatedDiv = new HtmlGenericControl("div");
        generatedDiv.Attributes["id"] = generatedivid;
        generatedDiv.Attributes["style"] = "visibility:visible;";
        generatedDiv.InnerHtml = "<div id='light' class='white_content'>";
        generatedDiv.InnerHtml += "<div class='popbrdwhite'>";
        generatedDiv.InnerHtml += "<div class='popbrdblack'>";
        generatedDiv.InnerHtml += "<table width='435' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td><table width='435' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='132' class='poptitle' style='padding-bottom:7px;'>Brochures</td>";
        generatedDiv.InnerHtml += "<td width='118' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='26' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='119' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='40' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td valign='top'>Additional Info</td>";
        generatedDiv.InnerHtml += "<td colspan='4'><textarea name='textarea' class='popfild' style='width:290px; height:80px;' id='txtarea_" + splitid[2] + "'>" + addinf0 + "</textarea></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td style='padding: 10px 0 0 132px;'>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoOk' href='#' id='" + generateOkHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/ok_btn.jpg' alt='' title='' style='margin-right:5px;' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoclose' href='#' id='" + generateCloseHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/cl_btn.jpg' border='0' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "<div id='fade' class='black_overlay'>";
        generatedDiv.InnerHtml += "</div>";

        bcdiv.Controls.Add(generatedDiv);
    }

    protected void SubmitDivBC_Click(object sender, EventArgs e)
    {
        string str = BCGetValues.Value;
        string[] htmlval = str.Split('~');
        int i = campaign.campaign_id;

        BrochureMoreInfo bc; 

        var getorderid = (from a in tlfp.GetTable<Order>()
                          where a.campaign_id == campaign.campaign_id && a.service_id == Int32.Parse(htmlval[0].ToString())
                          select a).Single();

        var searchBCTable = from b in tlfp.GetTable<BrochureMoreInfo>()
                             where b.ServiceID == Int32.Parse(htmlval[0].ToString()) && b.OrderID == getorderid.order_id
                             select b;

        if (searchBCTable.Count() == 0)
        {
            bc = new BrochureMoreInfo();
            
            bc.ServiceID = Int32.Parse(htmlval[0].ToString());
            bc.OrderID = getorderid.order_id;
            bc.AdditionalInfo = htmlval[1].ToString();

            tlfp.GetTable<BrochureMoreInfo>().InsertOnSubmit(bc);
        }
        else
        {
            bc = searchBCTable.Single();
            bc.AdditionalInfo = htmlval[1].ToString();
        }
        
        tlfp.SubmitChanges();        
    }

    protected void GenerateDivMM_Click(object sender, EventArgs e)
    {
        saveProposedShoppingCart();

        string getid = MMngMoreInfoLinkID.Value;
        string[] splitid = getid.Split('_');
        string generatedivid = splitid[0] + "Div" + splitid[2];
        string generateOkHyperlinkid = splitid[0] + "_moreinfoOk_" + splitid[2];
        string generateCloseHyperlinkid = splitid[0] + "_moreinfoClose_" + splitid[2];

        int serviceid = Int32.Parse(splitid[2]);

        var orderid = (from a in tlfp.GetTable<Order>()
                       where a.campaign_id == campaign.campaign_id && a.service_id == serviceid
                       select a).Single();

        var searchBCTable = from b in tlfp.GetTable<MediaMngMoreInfo>()
                            where b.service_id == serviceid && b.order_id == orderid.order_id
                            select b;

        string addinf0 = "";

        if (searchBCTable.Count() > 0)
        {
            addinf0 = searchBCTable.Single().AdditionalInfo.ToString();
        }

        HtmlGenericControl generatedDiv = new HtmlGenericControl("div");
        generatedDiv.Attributes["id"] = generatedivid;
        generatedDiv.Attributes["style"] = "visibility:visible;";
        generatedDiv.InnerHtml = "<div id='light' class='white_content'>";
        generatedDiv.InnerHtml += "<div class='popbrdwhite'>";
        generatedDiv.InnerHtml += "<div class='popbrdblack'>";
        generatedDiv.InnerHtml += "<table width='435' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td><table width='435' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='132' class='poptitle' style='padding-bottom:7px;'>Media Management</td>";
        generatedDiv.InnerHtml += "<td width='118' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='26' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='119' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "<td width='40' class='poptitle' style='padding-bottom:7px;'>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td valign='top'>Additional Info</td>";
        generatedDiv.InnerHtml += "<td colspan='4'><textarea name='textarea' class='popfild' style='width:290px; height:80px;' id='txtarea_" + splitid[2] + "'>" + addinf0 + "</textarea></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td style='padding: 10px 0 0 132px;'>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoOk' href='#' id='" + generateOkHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/ok_btn.jpg' alt='' title='' style='margin-right:5px;' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoclose' href='#' id='" + generateCloseHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/cl_btn.jpg' border='0' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "<div id='fade' class='black_overlay'>";
        generatedDiv.InnerHtml += "</div>";

        bcdiv.Controls.Add(generatedDiv);
    }

    protected void SubmitDivMM_Click(object sender, EventArgs e)
    {
        string str = MMngGetValues.Value;
        string[] htmlval = str.Split('~');
        int i = campaign.campaign_id;

        MediaMngMoreInfo bc;

        var getorderid = (from a in tlfp.GetTable<Order>()
                          where a.campaign_id == campaign.campaign_id && a.service_id == Int32.Parse(htmlval[0].ToString())
                          select a).Single();

        var searchBCTable = from b in tlfp.GetTable<MediaMngMoreInfo>()
                            where b.service_id == Int32.Parse(htmlval[0].ToString()) && b.order_id == getorderid.order_id
                            select b;

        if (searchBCTable.Count() == 0)
        {
            bc = new MediaMngMoreInfo();

            bc.service_id = Int32.Parse(htmlval[0].ToString());
            bc.order_id = getorderid.order_id;
            bc.AdditionalInfo = htmlval[1].ToString();

            tlfp.GetTable<MediaMngMoreInfo>().InsertOnSubmit(bc);
        }
        else
        {
            bc = searchBCTable.Single();
            bc.AdditionalInfo = htmlval[1].ToString();
        }

        tlfp.SubmitChanges();
    }

    protected void GenerateDivBRD_Click(object sender, EventArgs e)
    {
        saveProposedShoppingCart();

        string getid = BRDMoreInfoLinkID.Value;
        string[] splitid = getid.Split('_');
        string generatedivid = splitid[0] + "Div" + splitid[2];
        string generateOkHyperlinkid = splitid[0] + "_moreinfoOk_" + splitid[2];
        string generateCloseHyperlinkid = splitid[0] + "_moreinfoClose_" + splitid[2];

        int serviceid = Int32.Parse(splitid[2]);

        var orderid = (from a in tlfp.GetTable<Order>()
                       where a.campaign_id == campaign.campaign_id && a.service_id == serviceid
                       select a).Single();

        var searchBrdTable = from b in tlfp.GetTable<BoardMoreInfo>()
                            where b.ServiceID == serviceid && b.OrderID == orderid.order_id
                            select b;

        string address = "", agency = "", qty = "", installtype = "", vipservice = "", installdate = "", installinstr = "";
        string chk1 = "", chk2 = "", chk3 = "", chk4 = "", vipserv= "";

        if (searchBrdTable.Count() > 0)
        {
            address = searchBrdTable.Single().Address.ToString();
            agency = searchBrdTable.Single().Agency.ToString();
            qty = searchBrdTable.Single().Qty.ToString();

            if (searchBrdTable.Single().InstallType != null)
                installtype = searchBrdTable.Single().InstallType.ToString();

            if (installtype.ToUpper().Trim() == "STANDARD")
                chk1 = "checked='checked'";
            else if (installtype.ToUpper().Trim() == "FLAT ON WALL")
                chk2 = "checked='checked'";
            else if (installtype.ToUpper().Trim() == "ON AWNING")
                chk3 = "checked='checked'";
            else if (installtype.ToUpper().Trim() == "V-SHAPE")
                chk4 = "checked='checked'";

            vipservice = searchBrdTable.Single().VipService.ToString();

            if (vipservice.ToLower() == "true")
                vipserv = "checked='checked'";

            installdate = String.Format("{0:dd/MM/yyyy}", searchBrdTable.Single().InstallDate);
            installinstr = searchBrdTable.Single().InstallInstructions.ToString();
        }

        HtmlGenericControl generatedDiv = new HtmlGenericControl("div");
        generatedDiv.Attributes["id"] = generatedivid;
        generatedDiv.Attributes["style"] = "visibility:visible;";
        generatedDiv.InnerHtml = "<div id='light' class='whiteBoard'>";
        generatedDiv.InnerHtml += "<div class='popbrdwhite'>";
        generatedDiv.InnerHtml += "<div class='popbrdblack'>";
        generatedDiv.InnerHtml += "<table width='565' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td colspan='2' class='poptitle' style='padding-bottom:7px;'>Board</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='117'>Address</td>";
        generatedDiv.InnerHtml += "<td><input type='text' class='popfild' style='width:450px;' id='txtaddress_" + splitid[2] + "' value='" + address + "'></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Agency</td>";
        generatedDiv.InnerHtml += "<td><input type='text'  class='popfild' style='width:450px;'  id='txtagency_" + splitid[2] + "'value='" + agency + "'></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td valign='top'>Qyt</td>";
        generatedDiv.InnerHtml += "<td style='padding-top:0;'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='83%'><input type='text'  class='popfild'  id='txtqty_" + splitid[2] + "' value='" + qty + "'/></td>";
        generatedDiv.InnerHtml += "<td width='18%'></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td align='left' valign='top'>Install Type</td>";
        generatedDiv.InnerHtml += "<td style='padding-top:0;'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='4%'><input type='radio' name='checkbox' id='txtchk1_" + splitid[2] + "' " + chk1 + " /></td>";
        generatedDiv.InnerHtml += "<td width='78%'>Standard</td>";
        generatedDiv.InnerHtml += "<td width='18%'>Included</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td><input type='radio' name='checkbox' id='txtchk2_" + splitid[2] + "' " + chk2 + " /></td>";
        generatedDiv.InnerHtml += "<td>Flat On Wall (Street Level)</td>";
        generatedDiv.InnerHtml += "<td width='18%'>Included</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td><input type='radio' name='checkbox' id='txtchk3_" + splitid[2] + "' " + chk3 + "  /></td>";
        generatedDiv.InnerHtml += "<td>On Awning</td>";
        generatedDiv.InnerHtml += "<td>+$110</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td><input type='radio' name='checkbox' id='txtchk4_" + splitid[2] + "' " + chk4 + "  /></td>";
        generatedDiv.InnerHtml += "<td>V-shape (off wall)</td>";
        generatedDiv.InnerHtml += "<td>+$110</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td align='left' valign='top'>VIP Services</td>";
        generatedDiv.InnerHtml += "<td style='padding-top:0;'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='4%'><input type='checkbox' name='checkbox5' id='txtchk5_" + splitid[2] + "' " + vipserv + " /></td>";
        generatedDiv.InnerHtml += "<td width='78%'>Same day (ordered by 11.00am) or saturday installs.</td>";
        generatedDiv.InnerHtml += "<td width='18%'>+$80</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td colspan='2'>Orders processed after 2.00pm will be carried to the following day</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td align='left' valign='top'>Install Date</td>";
        generatedDiv.InnerHtml += "<td><input type='text'  class='calenderdate' id='txtinstalldate_" + splitid[2] + "' value='"+ installdate +"' />&nbsp;<img src='images/calender.gif' alt='' title='' /></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td align='left' valign='top'>Install Instructions</td>";
        generatedDiv.InnerHtml += "<td><textarea class='popfild' style='width:450px; height:80px;' id='txtinstructions_" + splitid[2] + "'>" + installinstr + "</textarea></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td align='left' valign='top'>&nbsp</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoOk' href='#' id='" + generateOkHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/ok_btn.jpg' alt='' title='' style='margin-right:5px;' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoclose' href='#' id='" + generateCloseHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/cl_btn.jpg' border='0' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "<div id='fade' class='black_overlay'>";
        generatedDiv.InnerHtml += "</div>";

        brddiv.Controls.Add(generatedDiv);
    }

    protected void SubmitDivBRD_Click(object sender, EventArgs e)
    {
        string str = BRDGetValues.Value;
        string[] htmlval = str.Split('~');
        int i = campaign.campaign_id;        

        BoardMoreInfo brd; 

        var getorderid = (from a in tlfp.GetTable<Order>()
                          where a.campaign_id == campaign.campaign_id && a.service_id == Int32.Parse(htmlval[0].ToString())
                          select a).Single();

        var searchBrdTable = from b in tlfp.GetTable<BoardMoreInfo>()
                             where b.ServiceID == Int32.Parse(htmlval[0].ToString()) && b.OrderID == getorderid.order_id
                             select b;

        if (searchBrdTable.Count() == 0)
        {
            brd = new BoardMoreInfo();

            brd.ServiceID = Int32.Parse(htmlval[0].ToString());
            brd.OrderID = getorderid.order_id;
            brd.Address = htmlval[1].ToString();
            brd.Agency = htmlval[2].ToString();
            brd.Qty = htmlval[3].ToString();

            if (htmlval[4].ToString() == "true")
                brd.InstallType = "STANDARD";
            else if (htmlval[5].ToString() == "true")
                brd.InstallType = "FLAT ON WALL";
            else if (htmlval[6].ToString() == "true")
                brd.InstallType = "ON AWNING";
            else if (htmlval[7].ToString() == "true")
                brd.InstallType = "V-SHAPE";

            if (htmlval[8].ToString().ToLower() == "true")
                brd.VipService = true;
            else
                brd.VipService = false;

            if (htmlval[9].ToString() != "")
                brd.InstallDate = DateTime.Parse(htmlval[9].ToString());
            
            brd.InstallInstructions = htmlval[10].ToString();

            tlfp.GetTable<BoardMoreInfo>().InsertOnSubmit(brd);
        }
        else
        {
            brd = searchBrdTable.Single();

            brd.Address = htmlval[1].ToString();
            brd.Agency = htmlval[2].ToString();
            brd.Qty = htmlval[3].ToString();

            if (htmlval[4].ToString() == "true")
                brd.InstallType = "STANDARD";
            else if (htmlval[5].ToString() == "true")
                brd.InstallType = "FLAT ON WALL";
            else if (htmlval[6].ToString() == "true")
                brd.InstallType = "ON AWNING";
            else if (htmlval[7].ToString() == "true")
                brd.InstallType = "V-SHAPE";

            if (htmlval[8].ToString().ToLower() == "true")
                brd.VipService = true;
            else
                brd.VipService = false;

            if (htmlval[9].ToString() != "")
                brd.InstallDate = DateTime.Parse(htmlval[9].ToString());
            
            brd.InstallInstructions = htmlval[10].ToString();
        }

        tlfp.SubmitChanges();

        saveProposedShoppingCart();
    }

    protected void GeneratePackage_Click(object sender, EventArgs e)
    {
        saveProposedShoppingCart();

        string getid = PkgMoreInfoLinkID.Value;
        string[] splitid = getid.Split('_');
        string generatedivid = splitid[0] + "Div" + splitid[2];
        string generateOkHyperlinkid = splitid[0] + "_moreinfoOk_" + splitid[2];
        string generateCloseHyperlinkid = splitid[0] + "_moreinfoClose_" + splitid[2];

        string strdate = "", strtime = "", artdate = "", boarddate = "", brochuredate = "", bcinstr = "", addinf0 = "", file1 = "", file2 = "", file3 = "", file4 = "", file5 = "", daytime = "", h = "0", m = "0";

        int serviceid = Int32.Parse(splitid[2]);

        var orderid = (from a in tlfp.GetTable<Order>()
                       where a.campaign_id == campaign.campaign_id && a.service_id == serviceid
                       select a).Single();

        var searchPkgTable = from b in tlfp.GetTable<PackageMoreInfo>()
                            where b.ServiceID == serviceid && b.OrderID == orderid.order_id
                            select b;

        if (searchPkgTable.Count() > 0)
        {
            strdate = String.Format("{0:dd/MM/yyyy}", searchPkgTable.Single().ServiceDate);
            strtime = searchPkgTable.Single().ServiceTime.ToString();
            string[] time = strtime.Split('-');

            if (strtime.IndexOf('-') > 0)
            {
                h = time[0];
                m = time[1];
                daytime = time[2];
            }

            artdate = String.Format("{0:dd/MM/yyyy}", searchPkgTable.Single().ArtworkDate);
            boarddate = String.Format("{0:dd/MM/yyyy}", searchPkgTable.Single().BoardDate);
            brochuredate = String.Format("{0:dd/MM/yyyy}", searchPkgTable.Single().BrochureDate);
            bcinstr = searchPkgTable.Single().BoardInstructions.ToString();
            addinf0 = searchPkgTable.Single().OtherInstructions.ToString();

            if (searchPkgTable.Single().file_1 != null)
                file1 = searchPkgTable.Single().file_1.ToString();

            if (searchPkgTable.Single().file_2 != null)
                file2 = searchPkgTable.Single().file_2.ToString();

            if (searchPkgTable.Single().file_3 != null)
                file3 = searchPkgTable.Single().file_3.ToString();

            if (searchPkgTable.Single().file_4 != null)
                file4 = searchPkgTable.Single().file_4.ToString();

            if (searchPkgTable.Single().file_5 != null)
                file5 = searchPkgTable.Single().file_5.ToString();
        }

        HtmlGenericControl generatedDiv = new HtmlGenericControl("div");
        generatedDiv.Attributes["id"] = generatedivid;
        generatedDiv.Attributes["style"] = "visibility:visible;";
        generatedDiv.InnerHtml = "<div id='light' class='whitePackage'>";
        generatedDiv.InnerHtml += "<div class='popbrdwhite'>";
        generatedDiv.InnerHtml += "<div class='popbrdblack'>";
        generatedDiv.InnerHtml += "<table width='475' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<table width='475' border='0' align='left' cellpadding='0' cellspacing='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='172' class='poptitle' style='padding-bottom: 7px;'>Package";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td width='118' class='poptitle' style='padding-bottom: 7px;'>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td width='26' class='poptitle' style='padding-bottom: 7px;'>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td width='119' class='poptitle' style='padding-bottom: 7px;'>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td width='40' class='poptitle' style='padding-bottom: 7px;'>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Service Required";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<input type='text' class='calenderdate' id='txtservice_" + splitid[2] + "' value='" + strdate + "' />";
        generatedDiv.InnerHtml += "</td>";


        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/calender.gif' width='18' height='18' /></td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Enter time</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<select id='hours'>";
        for (int i = 1; i < 13; i++)
        {
            if (i == Int32.Parse(h))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + i + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + i + "</option>";
        }
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";
        generatedDiv.InnerHtml += "<select id='minutes'>";

        for (int i = 0; i < 60; i = i + 15)
        {
            string timeval = i.ToString();

            if (timeval == "0")
                timeval = "00";

            if (i == Int32.Parse(m))
                generatedDiv.InnerHtml += "<option value='" + i + "' selected='selected'>" + timeval + "</option>";
            else
                generatedDiv.InnerHtml += "<option value='" + i + "' >" + timeval + "</option>";
        }

        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += ": &nbsp;";
        generatedDiv.InnerHtml += "<select id='daytime'>";
        if (daytime != "")
        {
            if (daytime == "AM")
            {
                generatedDiv.InnerHtml += "<option selected='selected'>AM</option>";
                generatedDiv.InnerHtml += "<option>PM</option>";
            }
            else
            {
                generatedDiv.InnerHtml += "<option>AM</option>";
                generatedDiv.InnerHtml += "<option selected='selected'>PM</option>";
            }
        }
        else
        {
            generatedDiv.InnerHtml += "<option>AM</option>";
            generatedDiv.InnerHtml += "<option>PM</option>";
        }
        generatedDiv.InnerHtml += "</select>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td colspan='3'><img src='images/icon_time.gif' alt='' title='' /></td>";
        generatedDiv.InnerHtml += "</tr>";
        
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Artwork Required";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<input type='text' class='calenderdate' id='txtart_" + splitid[2] + "' value='" + artdate + "' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<img src='images/calender.gif' width='18' height='18' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Board Required";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<input type='text' class='calenderdate' id='txtboard_" + splitid[2] + "' value='" + boarddate + "' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<img src='images/calender.gif' width='18' height='18' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";        
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Date Brochure Required";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<input type='text' class='calenderdate' id='txtbrochure_" + splitid[2] + "' value='" + brochuredate + "' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<img src='images/calender.gif' width='18' height='18' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Board install instructions";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td colspan='4'>";
        generatedDiv.InnerHtml += "<textarea name='textarea' class='popfild' style='width:290px; height:80px;' id='txtareaboard_" + splitid[2] + "'>" + bcinstr + "</textarea>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>Other instructions";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td colspan='4'>";
        generatedDiv.InnerHtml += "<textarea name='textarea' class='popfild' style='width:290px; height:80px;' id='txtareaother_" + splitid[2] + "'>" + addinf0 + "</textarea>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td align='left' valign='top'>File Upload";
        generatedDiv.InnerHtml += "<br />";
        generatedDiv.InnerHtml += "<span style='font-size: 10px; color: #999999; float: left;'>(Max 5 Uploads)</span>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td colspan='4' valign='top' style='padding-top: 0px;'>";
        generatedDiv.InnerHtml += "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td width='60%'>";
        generatedDiv.InnerHtml += "<input type='file' style='width: 250px;' id='file1_" + splitid[2] + "' name='file1_" + splitid[2] + "' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td width='20%'>&nbsp;&nbsp;";
        generatedDiv.InnerHtml += "<a href=''></a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<input type='file' style='width: 250px;' id='file2_" + splitid[2] + "' name='file2_" + splitid[2] + "' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;&nbsp;";
        generatedDiv.InnerHtml += "<a href=''></a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<input type='file' style='width: 250px;' id='file3_" + splitid[2] + "' name='file3_" + splitid[2] + "' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;&nbsp;";
        generatedDiv.InnerHtml += "<a href=''></a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<input type='file' style='width: 250px;' id='file4_" + splitid[2] + "' name='file4_" + splitid[2] + "' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;&nbsp;";
        generatedDiv.InnerHtml += "<a href=''></a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>";
        generatedDiv.InnerHtml += "<input type='file' style='width: 250px;' id='file5_" + splitid[2] + "' name='file5_" + splitid[2] + "' />";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td>&nbsp;&nbsp;";
        generatedDiv.InnerHtml += "<a href=''></a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "<tr>";
        generatedDiv.InnerHtml += "<td>&nbsp;&nbsp;";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "<td colspan='4'>";
        generatedDiv.InnerHtml += "<a class='getmoreinfoOk' href='#' id='" + generateOkHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/ok_btn.jpg' alt='' title='' style='margin-right: 5px;' />";
        generatedDiv.InnerHtml += "</a>";generatedDiv.InnerHtml += "<a class='getmoreinfoclose' href='#' id='" + generateCloseHyperlinkid + "'>";
        generatedDiv.InnerHtml += "<img src='images/cl_btn.jpg' border='0' />";
        generatedDiv.InnerHtml += "</a>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</td>";
        generatedDiv.InnerHtml += "</tr>";
        generatedDiv.InnerHtml += "</table>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "</div>";
        generatedDiv.InnerHtml += "<div id='fade' class='black_overlay'>";
        generatedDiv.InnerHtml += "</div>";

        brddiv.Controls.Add(generatedDiv);
    }

    protected void SubmitDivPkg_Click(object sender, EventArgs e)
    {
        string str = PkgGetValues.Value;
        string[] htmlval = str.Split('~');
        int i = campaign.campaign_id;

        var getorderid = (from a in tlfp.GetTable<Order>()
                          where a.campaign_id == campaign.campaign_id && a.service_id == Int32.Parse(htmlval[0].ToString())
                          select a).Single();

        var searchPkgTable = from b in tlfp.GetTable<PackageMoreInfo>()
                             where b.ServiceID == Int32.Parse(htmlval[0].ToString()) && b.OrderID == getorderid.order_id
                             select b;

        var getpropid = (from p in tlfp.GetTable<Campaign>()
                         where p.campaign_id == campaign.campaign_id
                         select p.property_id).Single();

        var getaddr = (from addr in tlfp.GetTable<Property>()
                       where addr.property_id == getpropid
                       select addr).Single();

        int agentGroupID = Convert.ToInt32(Session[FormContract.AGENT_GROUP_ID]);
        this.group = Agent_Group.GetAgentGroup(agentGroupID);

        string path = Server.MapPath("~/" + group.agent_group_name + "/" + getaddr.property_id + " " + getaddr.address1 + " " + getaddr.address2 + " " + getaddr.suburb + "\\UploadedFiles\\");

        HttpPostedFile file1 = Request.Files["file1_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[8].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file1.FileName);
            file1.SaveAs(path + fname);
        }

        HttpPostedFile file2 = Request.Files["file2_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[9].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file2.FileName);
            file2.SaveAs(path + fname);
        }

        HttpPostedFile file3 = Request.Files["file3_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[10].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file3.FileName);
            file3.SaveAs(path + fname);
        }

        HttpPostedFile file4 = Request.Files["file4_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[11].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file4.FileName);
            file4.SaveAs(path + fname);
        }

        HttpPostedFile file5 = Request.Files["file5_" + Int32.Parse(htmlval[0].ToString())];

        if (htmlval[12].ToString().Trim() != "")
        {
            string fname = System.IO.Path.GetFileName(file5.FileName);
            file5.SaveAs(path + fname);
        }

        PackageMoreInfo pkg;

        if (searchPkgTable.Count() == 0)
        {
            pkg = new PackageMoreInfo();

            pkg.ServiceID = Int32.Parse(htmlval[0].ToString());
            pkg.OrderID = getorderid.order_id;

            if (htmlval[1].ToString() != "")
                pkg.ServiceDate = DateTime.Parse(htmlval[1].ToString());

            pkg.ServiceTime = htmlval[2].ToString();

            if (htmlval[3].ToString() != "")
                pkg.ArtworkDate = DateTime.Parse(htmlval[3].ToString());

            if (htmlval[4].ToString() != "")
                pkg.BoardDate = DateTime.Parse(htmlval[4].ToString());

            if (htmlval[5].ToString() != "")
                pkg.BrochureDate = DateTime.Parse(htmlval[5].ToString());

            pkg.BoardInstructions = htmlval[6].ToString();
            pkg.OtherInstructions = htmlval[7].ToString();

            if (htmlval[8].ToString() != "")
            {
                int index1 = htmlval[8].ToString().LastIndexOf("\\");
                string filname1 = htmlval[8].ToString().Substring(index1 + 1);
                pkg.file_1 = filname1;
            }

            if (htmlval[9].ToString() != "")
            {
                int index2 = htmlval[9].ToString().LastIndexOf("\\");
                string filname2 = htmlval[9].ToString().Substring(index2 + 1);
                pkg.file_2 = filname2;
            }

            if (htmlval[10].ToString() != "")
            {
                int index3= htmlval[10].ToString().LastIndexOf("\\");
                string filname3 = htmlval[10].ToString().Substring(index3 + 1);
                pkg.file_3 = filname3;
            }

            if (htmlval[11].ToString() != "")
            {
                int index4 = htmlval[11].ToString().LastIndexOf("\\");
                string filname4 = htmlval[11].ToString().Substring(index4 + 1);
                pkg.file_4 = filname4;
            }

            if (htmlval[12].ToString() != "")
            {
                int index5 = htmlval[12].ToString().LastIndexOf("\\");
                string filname5 = htmlval[12].ToString().Substring(index5 + 1);
                pkg.file_5 = filname5;
            }

            tlfp.GetTable<PackageMoreInfo>().InsertOnSubmit(pkg);
        }
        else
        {
            pkg = searchPkgTable.Single();

            if (htmlval[1].ToString() != "")
                pkg.ServiceDate = DateTime.Parse(htmlval[1].ToString());

            pkg.ServiceTime = htmlval[2].ToString();

            if (htmlval[3].ToString() != "")
                pkg.ArtworkDate = DateTime.Parse(htmlval[3].ToString());

            if (htmlval[4].ToString() != "")
                pkg.BoardDate = DateTime.Parse(htmlval[4].ToString());

            if (htmlval[5].ToString() != "")
                pkg.BrochureDate = DateTime.Parse(htmlval[5].ToString());

            pkg.BoardInstructions = htmlval[6].ToString();
            pkg.OtherInstructions = htmlval[7].ToString();

            if (htmlval[8].ToString() != "")
            {
                int index1 = htmlval[8].ToString().LastIndexOf("\\");
                string filname1 = htmlval[8].ToString().Substring(index1 + 1);
                pkg.file_1 = filname1;
            }

            if (htmlval[9].ToString() != "")
            {
                int index2 = htmlval[9].ToString().LastIndexOf("\\");
                string filname2 = htmlval[9].ToString().Substring(index2 + 1);
                pkg.file_2 = filname2;
            }

            if (htmlval[10].ToString() != "")
            {
                int index3 = htmlval[10].ToString().LastIndexOf("\\");
                string filname3 = htmlval[10].ToString().Substring(index3 + 1);
                pkg.file_3 = filname3;
            }

            if (htmlval[11].ToString() != "")
            {
                int index4 = htmlval[11].ToString().LastIndexOf("\\");
                string filname4 = htmlval[11].ToString().Substring(index4 + 1);
                pkg.file_4 = filname4;
            }

            if (htmlval[12].ToString() != "")
            {
                int index5 = htmlval[12].ToString().LastIndexOf("\\");
                string filname5 = htmlval[12].ToString().Substring(index5 + 1);
                pkg.file_5 = filname5;
            }
        }

        tlfp.SubmitChanges();
    }

    private void SendOrderEmail()
    {
        for (int p = 0; p < 2; p++)
        {
            HtmlGenericControl divContent = new HtmlGenericControl("div");
            ToolboxDataContext tdc = new ToolboxDataContext();
            this.campaign = Campaign.GetCurrentCampaignByProperty(this.propertyID);
            Toolbox_User _user = (Toolbox_User)Session[FormContract.USER];

            var agent = (from a in tdc.Agents
                         where a.agent_id == this.campaign.agent_id
                         select a).Single();

            divContent.InnerHtml += "<table width='100%'>";
            divContent.InnerHtml += "<tr><td>";
            divContent.InnerHtml += "<table><tr><td colspan='2'><b>Customer Details </b></td></tr>";
            divContent.InnerHtml += "<tr><td><b>User Name </b></td><td>" + _user.user_name + "</td></tr>";
            divContent.InnerHtml += "<tr><td><b>Email </b></td><td>" + _user.Email + "</td></tr></table>";
            divContent.InnerHtml += "</td>";
            divContent.InnerHtml += "<td>";
            divContent.InnerHtml += "<table><tr><td colspan='2'><b>Listing Agent Details </b></td></tr>";
            divContent.InnerHtml += "<tr><td><b>Agent Name </b></td><td>" + agent.agent_name + "</td></tr>";
            divContent.InnerHtml += "<tr><td><b>Phone </b></td><td>" + agent.contact_number + "</td></tr></table>";
            divContent.InnerHtml += "</td>";
            divContent.InnerHtml += "</tr><tr><td colspan='2'><hr /></td></tr>";

            divContent.InnerHtml += "<tr><td colspan='2'>";
            divContent.InnerHtml += "<table><tr><td colspan='2'><b>Property Details </b></td></tr>";
            divContent.InnerHtml += "<tr><td><b>Address </b></td><td>" + propertyInfo.InnerHtml + "</td></tr></table>";
            divContent.InnerHtml += "</td></tr><tr><td colspan='2'><hr /></td></tr>";
            divContent.InnerHtml += "<tr><td colspan='2'>";
            divContent.InnerHtml += "<table><tr><td colspan='2'><b>Order Details </b></td></tr>";
            //divContent.InnerHtml += "<tr><td><b>Ordered Item </b></td><td>{item}</td></tr>";
            divContent.InnerHtml += "<tr><td><b>Requested Date </b></td><td>" + DateTime.Now.ToShortDateString() + "</td></tr></table>";
            divContent.InnerHtml += "</td>";
            divContent.InnerHtml += "</tr>";
            divContent.InnerHtml += "</table>";

            var category = from sc in tdc.Service_Categories
                           join s in tdc.Services on sc.service_category_id equals s.service_category_id
                           join o in tdc.Orders on s.service_id equals o.service_id
                           where o.campaign_id == campaign.campaign_id
                           select sc;

            var distCategory = category.Distinct();

           
            decimal total = 0;
            decimal otheramt = 0;
            IDictionary<int,Service_Category> serviceCategoryLookups =  Service_Category.LoadServiceCategories(Convert.ToInt32(Session[FormContract.AGENT_GROUP_ID]));
            //foreach (int newindex in newlist.Keys)
            //{
            //    int val = newlist[newindex];
               //foreach(int val in  
               // var findrow = (from sc in tdc.GetTable<Service_Category>()
               //                where sc.service_category_id == val  
               //                select sc).Single();
            foreach(int key in serviceCategoryLookups.Keys){

                //Service_Category row = findrow;
                Service_Category row = serviceCategoryLookups[key];

                divContent.InnerHtml += "<br /><br /><br /><div class='technology'><table><tr><td><strong>" + row.service_category1 + "</strong></td></tr></table></div>";

                var service = from s in tdc.Services
                              join o in tdc.Orders on s.service_id equals o.service_id
                              where s.service_category_id == Convert.ToInt32(row.service_category_id) && o.campaign_id == campaign.campaign_id
                              select new { s.service_id, o.order_id, s.service_name, s.service_charge, s.service_category_id };
                
                divContent.InnerHtml += "<div class='thelanguage'>";
                string packageInof = "";
                
                foreach (var servicerow in service)
                {
                    total = total + servicerow.service_charge;

                    if (p == 0)
                    {
                        if (row.service_category1.Trim().ToLower() == "entry package"
                                || row.service_category1.Trim().ToLower() == "standard package"
                                || row.service_category1.Trim().ToLower() == "premium package"
                                || row.service_category1.Trim().ToLower() == "premium"
                                || row.service_category1.Trim().ToLower() == "intro package redhot deal"
                        )
                        {
                            divContent.InnerHtml += "<div style='padding: 0 0 0 35px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='150' align='left'><strong>&nbsp;Order ID: " + servicerow.order_id + "</strong></td><td width='600' align='left'><strong>" + servicerow.service_name + "</strong></td><td width='200'align='left'><strong><span>$ " + servicerow.service_charge.ToString("#.00") + "</span></strong></td></tr>";
                        }
                        else
                        {
                            if (servicerow.service_charge == 0)
                                divContent.InnerHtml += "<div style='padding: 0 0 0 35px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='150' align='left'><strong>&nbsp;Order ID: " + servicerow.order_id + "</strong></td><td  width='600' align='left'><strong>" + servicerow.service_name + "</strong></td><td width='200'align='left'><strong><span>Quote</span></strong></td></tr>";
                            else
                                divContent.InnerHtml += "<div style='padding: 0 0 0 35px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='150' align='left'><strong>&nbsp;Order ID: " + servicerow.order_id + "</strong></td><td  width='600' align='left'><strong>" + servicerow.service_name + "</strong></td><td width='200' align='left'><strong><span>$ " + servicerow.service_charge.ToString("#.00") + "</span></strong></td></tr>";
                        }
                    }
                    else
                    {
                        if (row.service_category1.Trim().ToLower() == "entry package"
                                || row.service_category1.Trim().ToLower() == "standard package"
                                || row.service_category1.Trim().ToLower() == "premium package"
                                || row.service_category1.Trim().ToLower() == "premium")
                        {
                            divContent.InnerHtml += "<div style='padding: 0 0 0 35px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='150' align='left'></td><td width='600' align='left'><strong>" + servicerow.service_name + "</strong></td><td width='200'align='left'><strong><span>$ " + servicerow.service_charge.ToString("#.00") + "</span></strong></td></tr>";
                        }
                        else
                        {
                            if (servicerow.service_charge == 0)
                                divContent.InnerHtml += "<div style='padding: 0 0 0 35px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='150' align='left'></td><td  width='600' align='left'><strong>" + servicerow.service_name + "</strong></td><td width='200'align='left'><strong><span>Quote</span></strong></td></tr>";
                            else
                                divContent.InnerHtml += "<div style='padding: 0 0 0 35px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='150' align='left'></td><td  width='600' align='left'><strong>" + servicerow.service_name + "</strong></td><td width='200' align='left'><strong><span>$ " + servicerow.service_charge.ToString("#.00") + "</span></strong></td></tr>";
                        }
                    }


                    //divContent.InnerHtml += "   <div class='thelanguage' style='margin-left:40px;'><br/>";

                    divContent.InnerHtml += "<tr><td>&nbsp;</td><td style='padding:0 0 0 20px;'>";

                    if (row.service_category1.ToLower().Equals("floorplan"))
                    {
                        var serviceMoreInfo = from f in tdc.FloorPlanMoreInfos
                                              where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                              select f;
                        if (serviceMoreInfo.Count() > 0)
                        {
                            divContent.InnerHtml += "<span style='font-size:13px;'>Service Date: ";

                            if (serviceMoreInfo.Single().ServiceDate.HasValue)
                                divContent.InnerHtml += serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";

                            string daytime = "", h = "0", m = "0";
                            string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                            string[] time = strtime.Split('-');

                            if (strtime.IndexOf('-') > 0)
                            {
                                h = time[0];
                                m = time[1];
                                daytime = time[2];
                            }

                            if (m == "0")
                                divContent.InnerHtml += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                            else
                                divContent.InnerHtml += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";

                            divContent.InnerHtml += "<br/> Art work Date: ";
                            
                            if(serviceMoreInfo.Single().ArtWorkDate.HasValue)
                                divContent.InnerHtml += serviceMoreInfo.Single().ArtWorkDate.Value.ToShortDateString() + "<br/>";


                            divContent.InnerHtml += "<br/> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";
                            if (serviceMoreInfo.Single().File_1 != null)
                                divContent.InnerHtml += "<br/> File1: {FilePath}" + serviceMoreInfo.Single().File_1;
                            if (serviceMoreInfo.Single().File_2 != null)
                                divContent.InnerHtml += "<br/> File2: {FilePath}" + serviceMoreInfo.Single().File_2;
                            if (serviceMoreInfo.Single().File_3 != null)
                                divContent.InnerHtml += "<br/> File3: {FilePath}" + serviceMoreInfo.Single().File_3;

                            divContent.InnerHtml += "</span>";
                        }
                        else
                            divContent.InnerHtml += "No extra information entered.";
                    }
                    else if (row.service_category1.ToLower().Equals("discount photo and plan combo"))
                    {
                        var serviceMoreInfo = from f in tdc.DiscountPhotoMoreInfos
                                              where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                              select f;
                        if (serviceMoreInfo.Count() > 0)
                        {
                            divContent.InnerHtml += "<span style='font-size:13px;'>Service Date: ";

                            if (serviceMoreInfo.Single().ServiceDate.HasValue)
                                divContent.InnerHtml += serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";


                            string daytime = "", h = "0", m = "0";
                            string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                            string[] time = strtime.Split('-');

                            if (strtime.IndexOf('-') > 0)
                            {
                                h = time[0];
                                m = time[1];
                                daytime = time[2];
                            }

                            if (m == "0")
                                divContent.InnerHtml += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                            else
                                divContent.InnerHtml += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";


                            divContent.InnerHtml += "<br/> Art work Date: ";

                            if (serviceMoreInfo.Single().ArtWorkDate.HasValue)
                                divContent.InnerHtml += serviceMoreInfo.Single().ArtWorkDate.Value.ToShortDateString() + "<br/>";

                            divContent.InnerHtml += "<br/> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";
                            if (serviceMoreInfo.Single().File_1 != null)
                                divContent.InnerHtml += "<br/> File1: {FilePath}" + serviceMoreInfo.Single().File_1;
                            if (serviceMoreInfo.Single().File_2 != null)
                                divContent.InnerHtml += "<br/> File2: {FilePath}" + serviceMoreInfo.Single().File_2;
                            if (serviceMoreInfo.Single().File_3 != null)
                                divContent.InnerHtml += "<br/> File3: {FilePath}" + serviceMoreInfo.Single().File_3;

                            divContent.InnerHtml += "</span>";
                        }
                        else
                            divContent.InnerHtml += "No extra information entered.";
                    }
                    else if (row.service_category1.ToLower().Equals("photography"))
                    {
                        var serviceMoreInfo = from f in tdc.PhotographyMoreInfos
                                              where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                              select f;
                        if (serviceMoreInfo.Count() > 0)
                        {
                            divContent.InnerHtml += "<span style='font-size:13px;'>Service Date: ";

                            if (serviceMoreInfo.Single().ServiceDate.HasValue)
                                divContent.InnerHtml += serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";


                            string daytime = "", h = "0", m = "0";
                            string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                            string[] time = strtime.Split('-');

                            if (strtime.IndexOf('-') > 0)
                            {
                                h = time[0];
                                m = time[1];
                                daytime = time[2];
                            }

                            if (m == "0")
                                divContent.InnerHtml += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                            else
                                divContent.InnerHtml += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";


                            divContent.InnerHtml += "<br/> Art work Date: ";

                            if (serviceMoreInfo.Single().ArtWorkDate.HasValue)
                                divContent.InnerHtml += serviceMoreInfo.Single().ArtWorkDate.Value.ToShortDateString() + "<br/>";

                            divContent.InnerHtml += "<br/> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";

                            divContent.InnerHtml += "</span>";
                        }
                        else
                            divContent.InnerHtml += "No extra information entered.";
                    }
                    else if (row.service_category1.ToLower().Equals("copywriting"))
                    {
                        var serviceMoreInfo = from f in tdc.CopyWritingMoreInfos
                                              where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                              select f;
                        if (serviceMoreInfo.Count() > 0)
                        {
                            divContent.InnerHtml += "<span style='font-size:13px;'>Service Date: ";

                            if (serviceMoreInfo.Single().ServiceDate.HasValue)
                                divContent.InnerHtml += serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";

                            string daytime = "", h = "0", m = "0";
                            string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                            string[] time = strtime.Split('-');

                            if (strtime.IndexOf('-') > 0)
                            {
                                h = time[0];
                                m = time[1];
                                daytime = time[2];
                            }

                            if (m == "0")
                                divContent.InnerHtml += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                            else
                                divContent.InnerHtml += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";

                            divContent.InnerHtml += "<br/> Art work Date: ";

                            if (serviceMoreInfo.Single().ArtWorkDate.HasValue)
                                divContent.InnerHtml += serviceMoreInfo.Single().ArtWorkDate.Value.ToShortDateString() + "<br/>";

                            divContent.InnerHtml += "<br/> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";
                            if (serviceMoreInfo.Single().File_1 != null)
                                divContent.InnerHtml += "<br/> File1: {FilePath}" + serviceMoreInfo.Single().File_1;

                            divContent.InnerHtml += "</span>";
                        }
                        else
                            divContent.InnerHtml += "No extra information entered.";
                    }
                    else if (row.service_category1.ToLower().Equals("other"))
                    {
                        var serviceMoreInfo = from f in tdc.OtherMoreInfos
                                              where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                              select f;
                        if (serviceMoreInfo.Count() > 0)
                        {
                            divContent.InnerHtml += "<br/> <span style='font-size:13px;'>Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";
                            divContent.InnerHtml += "</span>";
                        }
                        else
                            divContent.InnerHtml += "No extra information entered.";
                    }
                    else if (row.service_category1.ToLower().Equals("brochures"))
                    {
                        var serviceMoreInfo = from f in tdc.BrochureMoreInfos
                                              where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                              select f;
                        if (serviceMoreInfo.Count() > 0)
                        {
                            divContent.InnerHtml += "<br/><span style='font-size:13px;'>Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";
                            divContent.InnerHtml += "</span>";
                        }
                        else
                            divContent.InnerHtml += "No extra information entered.";
                    }
                    else if (row.service_category1.ToLower().Equals("boards"))
                    {
                        var serviceMoreInfo = from f in tdc.BoardMoreInfos
                                              where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                              select f;
                        if (serviceMoreInfo.Count() > 0)
                        {
                            divContent.InnerHtml += "<span style='font-size:13px;'>Address: " + serviceMoreInfo.Single().Address + "<br/>";
                            divContent.InnerHtml += "<br/> Agency: " + serviceMoreInfo.Single().Agency + "<br/>";
                            divContent.InnerHtml += "<br/> Qyt: " + serviceMoreInfo.Single().Qty + "<br/>";
                            //divContent.InnerHtml += "<br/> Install Type: " + serviceMoreInfo.Single().InstallType;
                            //if (serviceMoreInfo.Single().VipService.ToString().ToLower().Equals("true"))
                            //    divContent.InnerHtml += "<br/> VIP Services: Yes";
                            //else
                            //    divContent.InnerHtml += "<br/> VIP Services: No";

                            if (serviceMoreInfo.Single().InstallType != null)
                            {
                                if (serviceMoreInfo.Single().InstallType.Trim().ToUpper() == "ON AWNING" || serviceMoreInfo.Single().InstallType.Trim().ToUpper() == "V-SHAPE")
                                {
                                    divContent.InnerHtml += "<br/> Install Type ($110.00) : " + serviceMoreInfo.Single().InstallType + "<br/>";
                                    otheramt += 110;
                                }
                                else
                                {
                                    divContent.InnerHtml += "<br/> Install Type: " + serviceMoreInfo.Single().InstallType + "<br/>";
                                }
                            }

                            if (serviceMoreInfo.Single().VipService.ToString().ToLower().Equals("true"))
                            {
                                otheramt += 80;
                                divContent.InnerHtml += "<br/> VIP Services ($80.00) : Yes " + "<br/>";
                            }
                            else
                            {
                                divContent.InnerHtml += "<br/> VIP Services: No" + "<br/>";
                            }

                            divContent.InnerHtml += "<br/> Install Date: ";
                            
                            if(serviceMoreInfo.Single().InstallDate.HasValue)
                                divContent.InnerHtml += serviceMoreInfo.Single().InstallDate.Value.ToShortDateString() + "<br/>";

                            divContent.InnerHtml += "<br/> Install Instructions: " + serviceMoreInfo.Single().InstallInstructions.Replace("\r\n", "<br/>") + "<br/>";

                            divContent.InnerHtml += "</span>";
                        }
                        else
                            divContent.InnerHtml += "No extra information entered.";
                    }

                    divContent.InnerHtml += "<br/> ";

                    if (row.service_category1.Trim().ToLower() == "entry package"
                                         || row.service_category1.Trim().ToLower() == "standard package"
                                         || row.service_category1.Trim().ToLower() == "premium package"
                                         || row.service_category1.Trim().ToLower() == "premium")
                    {
                        var serviceMoreInfo = from f in tdc.PackageMoreInfos
                                              where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                              select f;
                        if (serviceMoreInfo.Count() > 0)
                        {
                            packageInof = "<br/><div style='padding: 0 0 0 20px; font-size:13px;' >" + row.service_category1 + "'s more info</div><br/>";
                            packageInof += "<span style='font-size:13px;'>";
                            
                            if(serviceMoreInfo.Single().ServiceDate.HasValue)
                                packageInof += "Service Date: " + serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";
                            
                            string daytime = "", h = "0", m = "0";
                            string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                            string[] time = strtime.Split('-');

                            if (strtime.IndexOf('-') > 0)
                            {
                                h = time[0];
                                m = time[1];
                                daytime = time[2];
                            }

                            if (m == "0")
                                packageInof += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                            else
                                packageInof += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";

                            packageInof += "<br/> Art work Date: ";

                            if (serviceMoreInfo.Single().ArtworkDate.HasValue)
                                packageInof += serviceMoreInfo.Single().ArtworkDate.Value.ToShortDateString() + "<br/>";
                            
                            packageInof += "<br/> Board Date: " + serviceMoreInfo.Single().BoardDate + "<br/>";
                            packageInof += "<br/> Brochure Date: " + serviceMoreInfo.Single().BrochureDate + "<br/>";
                            packageInof += "<br/> Board install instructions: " + serviceMoreInfo.Single().BoardInstructions.Replace("\r\n", "<br/>") + "<br/>";
                            packageInof += "<br/> Other instructions: " + serviceMoreInfo.Single().OtherInstructions.Replace("\r\n", "<br/>") + "<br/>";
                            if (serviceMoreInfo.Single().file_1 != null)
                                packageInof += "<br/> File1: {FilePath}" + serviceMoreInfo.Single().file_1;
                            if (serviceMoreInfo.Single().file_2 != null)
                                packageInof += "<br/> File2: {FilePath}" + serviceMoreInfo.Single().file_2;
                            if (serviceMoreInfo.Single().file_3 != null)
                                packageInof += "<br/> File3: {FilePath}" + serviceMoreInfo.Single().file_3;
                            if (serviceMoreInfo.Single().file_4 != null)
                                packageInof += "<br/> File4: {FilePath}" + serviceMoreInfo.Single().file_4;
                            if (serviceMoreInfo.Single().file_5 != null)
                                packageInof += "<br/> File5: {FilePath}" + serviceMoreInfo.Single().file_5;

                            packageInof += "</span>";
                            divContent.InnerHtml += packageInof + "</div>";
                        }
                        else
                            packageInof = "<br/>No extra information entered.";
                    }

                    divContent.InnerHtml += "</td><td>&nbsp;</td></tr></table></div></div>";
                }

                divContent.InnerHtml += "</div><br/>";
            }

            total += otheramt;
            divContent.InnerHtml += "<table><tr><td width='150'></td><td width='600'></td><td width='200'><b>Total: $ " + total.ToString("#.00") + "</b></td></div>";

            int agentGroupID = Convert.ToInt32(Session[FormContract.AGENT_GROUP_ID]);
            this.group = Agent_Group.GetAgentGroup(agentGroupID);

            if (p == 0)
            {
                Notifications emailAdmin = new Notifications("aaronb@iplan3d.com.au", "iplan3d - Orders", divContent.InnerHtml.ToString().Replace("{FilePath}", "~/" + group.agent_group_name + "/" + property.property_id + " " + property.address1 + " " + property.address2 + " " + property.suburb + "/UploadedFiles/"));
                //Notifications emailAdmin = new Notifications("kaushal.gajjar@datatechmedia.com", "iplan3d - Orders", divContent.InnerHtml.ToString().Replace("{FilePath}", "/office/" + property.address1 + " " + property.address2 + "/UploadedFiles/"));
                emailAdmin.SendEmail();
            }
            else
            {
                Notifications emailUser = new Notifications(_user.Email, "iplan3d - Orders", divContent.InnerHtml.ToString().Replace("{FilePath}", ""));
                //Notifications emailUser = new Notifications("kaushal.gajjar@datatechmedia.com", "iplan3d - Orders", divContent.InnerHtml.ToString().Replace("{FilePath}", ""));
                emailUser.SendEmail();
            }
        }
    }    

    private void SendOrder(int orderid, int serviceid)
    {
        HtmlGenericControl divContent = new HtmlGenericControl("div");
        ToolboxDataContext tdc = new ToolboxDataContext();
        this.campaign = Campaign.GetCurrentCampaignByProperty(this.propertyID);
        Toolbox_User _user = (Toolbox_User)Session[FormContract.USER];

        var agent = (from a in tdc.Agents
                     where a.agent_id == this.campaign.agent_id
                     select a).Single();

        var category = from sc in tdc.Service_Categories
                       join s in tdc.Services on sc.service_category_id equals s.service_category_id
                       join o in tdc.Orders on s.service_id equals o.service_id
                       where o.order_id == orderid
                       select sc;
        var row = category.Distinct().Single();

        var supplier = (from s in tdc.Suppliers
                        join ser in tdc.Services on s.supplier_id equals ser.supplier_id
                        where ser.service_id == serviceid
                        select s).Single();

        decimal total = 0;
        decimal otheramt = 0;

        divContent.InnerHtml += "<table width='100%'>";
        divContent.InnerHtml += "<tr><td><b>";
        divContent.InnerHtml += supplier.supplier_name + ", you have been assigned a new order from " + agent.Agent_Group.agent_group_name + " via Iplan3d ToolBox";
        divContent.InnerHtml += "</b></tr></td>";
        divContent.InnerHtml += "<tr><td>";
        divContent.InnerHtml += "<table><tr><td colspan='2'><b>Customer Details </b></td></tr>";
        divContent.InnerHtml += "<tr><td><b>User Name </b></td><td>" + _user.user_name + "</td></tr>";
        divContent.InnerHtml += "<tr><td><b>Email </b></td><td>" + _user.Email + "</td></tr></table>";
        divContent.InnerHtml += "</td>";
        divContent.InnerHtml += "<td>";
        divContent.InnerHtml += "<table><tr><td colspan='2'><b>Listing Agent Details </b></td></tr>";
        divContent.InnerHtml += "<tr><td><b>Agent Name </b></td><td>" + agent.agent_name + "</td></tr>";
        divContent.InnerHtml += "<tr><td><b>Phone </b></td><td>" + agent.contact_number + "</td></tr></table>";
        divContent.InnerHtml += "</td>";
        divContent.InnerHtml += "</tr><tr><td colspan='2'><hr /></td></tr>";

        divContent.InnerHtml += "<tr><td colspan='2'>";
        divContent.InnerHtml += "<table><tr><td colspan='2'><b>Property Details </b></td></tr>";
        divContent.InnerHtml += "<tr><td><b>Address </b></td><td>" + propertyInfo.InnerHtml + "</td></tr></table>";
        divContent.InnerHtml += "</td></tr><tr><td colspan='2'><hr /></td></tr>";
        divContent.InnerHtml += "<tr><td colspan='2'>";
        divContent.InnerHtml += "<table><tr><td colspan='2'><b>Order Details </b></td></tr>";
        //divContent.InnerHtml += "<tr><td><b>Ordered Item </b></td><td>{item}</td></tr>";
        divContent.InnerHtml += "<tr><td><b>Requested Date </b></td><td>" + DateTime.Now.ToShortDateString() + "</td></tr></table>";
        divContent.InnerHtml += "</td>";
        divContent.InnerHtml += "</tr>";
        divContent.InnerHtml += "</table>";

        divContent.InnerHtml += "<br /><br /><br /><div class='technology'><table><tr><td><strong>" + row.service_category1 + "</strong></td></tr></table></div>";
        var service = from s in tdc.Services
                      join o in tdc.Orders on s.service_id equals o.service_id
                      where s.service_id == serviceid && s.service_category_id == Convert.ToInt32(row.service_category_id) && o.campaign_id == campaign.campaign_id
                      select new { s.service_id, o.order_id, s.service_name, s.service_charge, s.service_category_id };
        divContent.InnerHtml += "<div class='thelanguage'>";
        string packageInof = "";
        foreach (var servicerow in service)
        {
            total = total + servicerow.service_charge;

            if (row.service_category1.Trim().ToLower() == "entry package"
                    || row.service_category1.Trim().ToLower() == "standard package"
                    || row.service_category1.Trim().ToLower() == "premium package"
                    || row.service_category1.Trim().ToLower() == "premium"
                        || row.service_category1.Trim().ToLower() == "intro package redhot deal"
                        )
            {
                //divContent.InnerHtml += "   <div style='margin-left:20px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='30'>&nbsp;</td><td width='50'>" + servicerow.order_id + "</td><td width='700'>" + servicerow.service_name + "</td><td width='200'><span>$ " + servicerow.service_charge.ToString("#.00") + "</span></td></tr></table></div></div>";
                divContent.InnerHtml += "<div style='padding: 0 0 0 35px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='150' align='left'></td><td width='600' align='left'><strong>" + servicerow.service_name + "</strong></td><td width='200'align='left'><strong><span>$ " + servicerow.service_charge.ToString("#.00") + "</span></strong></td></tr>";
            }
            else
            {
                if (servicerow.service_charge == 0)
                    divContent.InnerHtml += "<div style='padding: 0 0 0 35px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='150' align='left'></td><td  width='600' align='left'><strong>" + servicerow.service_name + "</strong></td><td width='200'align='left'><strong><span>Quote</span></strong></td></tr>";
                else
                    divContent.InnerHtml += "<div style='padding: 0 0 0 35px;' class='Order_Cat'><div class='order_service'><table width='1000'><tr><td width='150' align='left'></td><td  width='600' align='left'><strong>" + servicerow.service_name + "</strong></td><td width='200' align='left'><strong><span>$ " + servicerow.service_charge.ToString("#.00") + "</span></strong></td></tr>";
            }

            //divContent.InnerHtml += "   <div class='thelanguage' style='margin-left:40px;'><br/>";

            divContent.InnerHtml += "<tr><td>&nbsp;</td><td style='padding:0 0 0 20px;'>";

            if (row.service_category1.ToLower().Equals("floorplan"))
            {
                var serviceMoreInfo = from f in tdc.FloorPlanMoreInfos
                                      where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                      select f;
                if (serviceMoreInfo.Count() > 0)
                {
                    divContent.InnerHtml += "<span style='font-size:13px;'>Service Date: ";

                    if (serviceMoreInfo.Single().ServiceDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";

                    string daytime = "", h = "0", m = "0";
                    string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                    string[] time = strtime.Split('-');

                    if (strtime.IndexOf('-') > 0)
                    {
                        h = time[0];
                        m = time[1];
                        daytime = time[2];
                    }

                    if (m == "0")
                        divContent.InnerHtml += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                    else
                        divContent.InnerHtml += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";

                    divContent.InnerHtml += "<br/> Art work Date: ";

                    if (serviceMoreInfo.Single().ArtWorkDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().ArtWorkDate.Value.ToShortDateString() + "<br/>";

                    divContent.InnerHtml += "<br/> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";
                    if (serviceMoreInfo.Single().File_1 != null)
                        divContent.InnerHtml += "<br/> File1: {FilePath}" + serviceMoreInfo.Single().File_1;
                    if (serviceMoreInfo.Single().File_2 != null)
                        divContent.InnerHtml += "<br/> File2: {FilePath}" + serviceMoreInfo.Single().File_2;
                    if (serviceMoreInfo.Single().File_3 != null)
                        divContent.InnerHtml += "<br/> File3: {FilePath}" + serviceMoreInfo.Single().File_3;

                    divContent.InnerHtml += "</span>";
                }
                else
                    divContent.InnerHtml += "No extra information entered.";
            }
            else if (row.service_category1.ToLower().Equals("discount photo and plan combo"))
            {
                var serviceMoreInfo = from f in tdc.DiscountPhotoMoreInfos
                                      where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                      select f;
                if (serviceMoreInfo.Count() > 0)
                {

                    divContent.InnerHtml += "<span style='font-size:13px;'>Service Date: ";

                    if (serviceMoreInfo.Single().ServiceDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";

                    string daytime = "", h = "0", m = "0";
                    string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                    string[] time = strtime.Split('-');

                    if (strtime.IndexOf('-') > 0)
                    {
                        h = time[0];
                        m = time[1];
                        daytime = time[2];
                    }

                    if (m == "0")
                        divContent.InnerHtml += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                    else
                        divContent.InnerHtml += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";

                    divContent.InnerHtml += "<br/> Art work Date: ";

                    if (serviceMoreInfo.Single().ArtWorkDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().ArtWorkDate.Value.ToShortDateString() + "<br/>";

                    divContent.InnerHtml += "<br/> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";
                    if (serviceMoreInfo.Single().File_1 != null)
                        divContent.InnerHtml += "<br/> File1: {FilePath}" + serviceMoreInfo.Single().File_1;
                    if (serviceMoreInfo.Single().File_2 != null)
                        divContent.InnerHtml += "<br/> File2: {FilePath}" + serviceMoreInfo.Single().File_2;
                    if (serviceMoreInfo.Single().File_3 != null)
                        divContent.InnerHtml += "<br/> File3: {FilePath}" + serviceMoreInfo.Single().File_3;

                    divContent.InnerHtml += "</span>";
                }
                else
                    divContent.InnerHtml += "No extra information entered.";
            }
            else if (row.service_category1.ToLower().Equals("photography"))
            {
                var serviceMoreInfo = from f in tdc.PhotographyMoreInfos
                                      where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                      select f;
                if (serviceMoreInfo.Count() > 0)
                {
                    divContent.InnerHtml += "<span style='font-size:13px;'>Service Date: ";

                    if (serviceMoreInfo.Single().ServiceDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";

                    string daytime = "", h = "0", m = "0";
                    string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                    string[] time = strtime.Split('-');

                    if (strtime.IndexOf('-') > 0)
                    {
                        h = time[0];
                        m = time[1];
                        daytime = time[2];
                    }

                    if (m == "0")
                        divContent.InnerHtml += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                    else
                        divContent.InnerHtml += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";

                    divContent.InnerHtml += "<br/> Art work Date: ";

                    if (serviceMoreInfo.Single().ArtWorkDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().ArtWorkDate.Value.ToShortDateString() + "<br/>";

                    divContent.InnerHtml += "<br/> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";

                    divContent.InnerHtml += "</span>";
                }
                else
                    divContent.InnerHtml += "No extra information entered.";
            }
            else if (row.service_category1.ToLower().Equals("copywriting"))
            {
                var serviceMoreInfo = from f in tdc.CopyWritingMoreInfos
                                      where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                      select f;
                if (serviceMoreInfo.Count() > 0)
                {
                    divContent.InnerHtml += "<span style='font-size:13px;'>Service Date: ";

                    if (serviceMoreInfo.Single().ServiceDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";

                    string daytime = "", h = "0", m = "0";
                    string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                    string[] time = strtime.Split('-');

                    if (strtime.IndexOf('-') > 0)
                    {
                        h = time[0];
                        m = time[1];
                        daytime = time[2];
                    }

                    if (m == "0")
                        divContent.InnerHtml += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                    else
                        divContent.InnerHtml += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";

                    divContent.InnerHtml += "<br/> Art work Date: ";

                    if (serviceMoreInfo.Single().ArtWorkDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().ArtWorkDate.Value.ToShortDateString() + "<br/>";

                    divContent.InnerHtml += "<br/> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>") + "<br/>";
                    if (serviceMoreInfo.Single().File_1 != null)
                        divContent.InnerHtml += "<br/> File1: {FilePath}" + serviceMoreInfo.Single().File_1;

                    divContent.InnerHtml += "</span>";
                }
                else
                    divContent.InnerHtml += "No extra information entered.";
            }
            else if (row.service_category1.ToLower().Equals("other"))
            {
                var serviceMoreInfo = from f in tdc.OtherMoreInfos
                                      where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                      select f;
                if (serviceMoreInfo.Count() > 0)
                {
                    divContent.InnerHtml += "<br/><span style='font-size:13px;'> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>");
                    divContent.InnerHtml += "</span>";
                }
                else
                    divContent.InnerHtml += "No extra information entered.";
            }
            else if (row.service_category1.ToLower().Equals("brochures"))
            {
                var serviceMoreInfo = from f in tdc.BrochureMoreInfos
                                      where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                      select f;
                if (serviceMoreInfo.Count() > 0)
                {
                    divContent.InnerHtml += "<br/><span style='font-size:13px;'> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>");
                    divContent.InnerHtml += "</span>";
                }
                else
                    divContent.InnerHtml += "No extra information entered.";
            }
            else if (row.service_category1.ToLower().Equals("media management"))
            {
                List<MediaMngMoreInfo> serviceMoreInfo = MediaMngMoreInfo.GetRecordInfo(Convert.ToInt32(servicerow.order_id), Convert.ToInt32(servicerow.service_id));
                if (serviceMoreInfo.Count() > 0)
                {
                    divContent.InnerHtml += "<br/><span style='font-size:13px;'> Additional Info: " + serviceMoreInfo.Single().AdditionalInfo.Replace("\r\n", "<br/>");
                    divContent.InnerHtml += "</span>";
                }
                else
                    divContent.InnerHtml += "No extra information entered.";
            }
            else if (row.service_category1.ToLower().Equals("boards"))
            {
                var serviceMoreInfo = from f in tdc.BoardMoreInfos
                                      where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                      select f;
                if (serviceMoreInfo.Count() > 0)
                {
                    divContent.InnerHtml += "<span style='font-size:13px;'>Address: " + serviceMoreInfo.Single().Address + "<br/>";
                    divContent.InnerHtml += "<br/> Agency: " + serviceMoreInfo.Single().Agency + "<br/>";
                    divContent.InnerHtml += "<br/> Qyt: " + serviceMoreInfo.Single().Qty + "<br/>";

                    if (serviceMoreInfo.Single().InstallType != null)
                    {
                        if (serviceMoreInfo.Single().InstallType.Trim().ToUpper() == "ON AWNING" || serviceMoreInfo.Single().InstallType.Trim().ToUpper() == "V-SHAPE")
                        {
                            divContent.InnerHtml += "<br/> Install Type ($110.00) : " + serviceMoreInfo.Single().InstallType + "<br/>";
                            otheramt += 110;
                        }
                        else
                        {
                            divContent.InnerHtml += "<br/> Install Type: " + serviceMoreInfo.Single().InstallType + "<br/>";
                        }
                    }

                    if (serviceMoreInfo.Single().VipService.ToString().ToLower().Equals("true"))
                    {
                        otheramt += 80;
                        divContent.InnerHtml += "<br/> VIP Services ($80.00) : Yes " + "<br/>";
                    }
                    else
                    {
                        divContent.InnerHtml += "<br/> VIP Services: No" + "<br/>";
                    }

                    divContent.InnerHtml += "<br/> Install Date: ";

                    if (serviceMoreInfo.Single().InstallDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().InstallDate.Value.ToShortDateString() + "<br/>";

                    divContent.InnerHtml += "<br/> Install Instructions: " + serviceMoreInfo.Single().InstallInstructions.Replace("\r\n", "<br/>") + "<br/>";

                    divContent.InnerHtml += "</span>";
                }
                else
                    divContent.InnerHtml += "No extra information entered.";
            }

            divContent.InnerHtml += "<br/> ";
            divContent.InnerHtml += "</div>";

            if (row.service_category1.Trim().ToLower() == "entry package"
                                 || row.service_category1.Trim().ToLower() == "standard package"
                                 || row.service_category1.Trim().ToLower() == "premium package"
                                 || row.service_category1.Trim().ToLower() == "premium"
                        || row.service_category1.Trim().ToLower() == "intro package redhot deal"
                        )
            {
                divContent.InnerHtml += "</div>";
                var serviceMoreInfo = from f in tdc.PackageMoreInfos
                                      where f.OrderID == Convert.ToInt32(servicerow.order_id) && f.ServiceID == Convert.ToInt32(servicerow.service_id)
                                      select f;
                if (serviceMoreInfo.Count() > 0)
                {

                    packageInof = "<br/><div style='padding: 0 0 0 20px;' >" + row.service_category1 + "'s more info</div><br/>";
                    
                    packageInof += "<span style='font-size:13px;'>Service Date: ";

                    if (serviceMoreInfo.Single().ServiceDate.HasValue)
                        packageInof += serviceMoreInfo.Single().ServiceDate.Value.ToShortDateString() + "<br/>";

                    string daytime = "", h = "0", m = "0";
                    string strtime = serviceMoreInfo.Single().ServiceTime.ToString();
                    string[] time = strtime.Split('-');

                    if (strtime.IndexOf('-') > 0)
                    {
                        h = time[0];
                        m = time[1];
                        daytime = time[2];
                    }

                    if (m == "0")
                        packageInof += "<br/> Service Time: " + h + ": 00: " + daytime + "<br/>";
                    else
                        packageInof += "<br/> Service Time: " + h + ": " + m + ": " + daytime + "<br/>";

                    divContent.InnerHtml += "<br/> Art work Date: ";

                    if (serviceMoreInfo.Single().ArtworkDate.HasValue)
                        divContent.InnerHtml += serviceMoreInfo.Single().ArtworkDate.Value.ToShortDateString() + "<br/>";

                    packageInof += "<br/> Board Date: " + serviceMoreInfo.Single().BoardDate + "<br/>";
                    packageInof += "<br/> Brochure Date: " + serviceMoreInfo.Single().BrochureDate + "<br/>";
                    packageInof += "<br/> Board install instructions: " + serviceMoreInfo.Single().BoardInstructions.Replace("\r\n", "<br/>") + "<br/>";
                    packageInof += "<br/> Other instructions: " + serviceMoreInfo.Single().OtherInstructions.Replace("\r\n", "<br/>") + "<br/>";

                    if (serviceMoreInfo.Single().file_1 != null)
                        packageInof += "<br/> File1: {FilePath}" + serviceMoreInfo.Single().file_1;
                    if (serviceMoreInfo.Single().file_2 != null)
                        packageInof += "<br/> File2: {FilePath}" + serviceMoreInfo.Single().file_2;
                    if (serviceMoreInfo.Single().file_3 != null)
                        packageInof += "<br/> File3: {FilePath}" + serviceMoreInfo.Single().file_3;
                    if (serviceMoreInfo.Single().file_4 != null)
                        packageInof += "<br/> File4: {FilePath}" + serviceMoreInfo.Single().file_4;
                    if (serviceMoreInfo.Single().file_5 != null)
                        packageInof += "<br/> File5: {FilePath}" + serviceMoreInfo.Single().file_5;
                    
                    packageInof += "</span>";
                    divContent.InnerHtml += packageInof + "</div>";
                }
                else
                    packageInof = "<br/>No extra information entered.";
            }

            divContent.InnerHtml += "</td><td>&nbsp;</td></tr></table></div></div>";
        }

        divContent.InnerHtml += "</div><br/>";

        total += otheramt;

        string emailsubject = service.Single().service_name;

        Notifications emailUser = new Notifications(supplier.supplier_email, "iplan3d - Orders: " + emailsubject + " from " + agent.agent_name, divContent.InnerHtml.ToString().Replace("{FilePath}", ""));
        //Notifications emailUser = new Notifications("kaushal.gajjar@datatechmedia.com", "iplan3d - Orders: " + emailsubject + " from " + agent.agent_name, divContent.InnerHtml.ToString().Replace("{FilePath}", ""));
        emailUser.SendEmail();
    }
}
